Trade counter does not work
Forums › ProRealTime English forum › ProBuilder support › Trade counter does not work
- This topic has 5 replies, 4 voices, and was last updated 1 year ago by Nicolas.
-
-
03/18/2023 at 5:15 PM #211712
Hello
I am trying to bild a counter to determine when the bad trades are made.
I started to evaluate wich day of the week, but its count wrong.
Here is an snippet from the code
if buycondition then
buy positionsize contract at market
tradecounterall=tradecounterall+1
Trigger = 1 //Trigger that a new position are open so you evalute the last one
endifOnce TradeCounterall =0
Once Trigger = 0
Once BadMondag=0
Once BadTisdag=0
Once BadOnsdag=0
Once BadTorsdag=0
Once BadFredag=0if Trigger = 1 then
if PositionPerf(1)< 0.0 then //If the last position whas bad count the day that trade whas made
if currentday =1 then
BadMondag=BadMondag+1
elsif currentday=2 then
BadTisdag=BadTisdag+1
elsif currentday=3 then
BadOnsdag=BadOnsdag+1
elsif Currentday=4 then
BadTorsdag=BadTorsdag+1
elsif Currentday=5 then
BadFredag=BadFredag+1
endifcurrentday=Currentdayofweek //Set th current day for next trade
Trigger=0
endifgraphonprice tradecounterall coloured(0,0,255,255) as “tradecounter”
graphonprice BadMondag coloured(0,0,255,255) as “Mondag”
graphonprice BadTisdag coloured(0,0,255,255) as “Tisdag”
graphonprice BadOnsdag coloured(0,0,255,255) as “Onsdag”
graphonprice BadTorsdag coloured(0,0,255,255) as “Torsdag”
graphonprice BadFredag coloured(0,0,255,255) as “Fredag”In the backtest I do, the calculator in the grah, for example tradecounterall, says that there have been 215 trades, and if I add upp all the bad days, it might be say 65pcs. But when I read the same values from the Detailed report it shows other numbers. Let say Totalt: 150, Losing:50.
What is wrong or can anyone suggest another way to do this?
03/19/2023 at 4:34 AM #21172203/19/2023 at 4:44 AM #21172303/19/2023 at 5:56 AM #211725PositionPerf returns the temporary gain or loss candle by candle.
To tell if a trade gained or lost you have to compare the current StrategyProfit with that of the prior candle.
03/19/2023 at 3:17 PM #211734Thanks for the replys.
I use PositionPerf(1) so it should count the profit from the last ended trade. No temporary gain.
However, I realized that i have the setting defparam cumulateorders = false.
So even if there was no trade taking place when the buconditions were valid, the counter counted up.
So I changed to
if buycondition then
buy positionsize contract at market
if not shortonmarket and not longonmarket then
Trigger = 1 //Trigger that a new position are open so you evalute the last one
tradecounterall=tradecounterall+1
endif
endifits works not perfect but good enough.
But I realy wanted to write something like
If cumulateorders=false and not shortonmarket and not longonmarket then
…….
elsif cumulateorders=true then
…….
endif
But the program does not accept it. I don´t know how to write to take the cumulateorders settings into account?
03/20/2023 at 10:34 AM #211778If you allow cumulating of orders, it means that you can be on market with more than 1 order at the same time, so just create a variable that count the quantity of BUY and quantity of SELLSHORT in a row, and reset that variables when you invert the trade direction.
-
AuthorPosts
Find exclusive trading pro-tools on