Strategy Profit not working in realtime
Forums › ProRealTime English forum › ProOrder support › Strategy Profit not working in realtime
- This topic has 9 replies, 2 voices, and was last updated 1 year ago by robertogozzi.
-
-
06/07/2022 at 10:05 AM #194829
Hi I have the code below to stop opening new positions when one of the positions in the day closed with loss more than 200 or profit more than 350.
It works perfectly in the proback test but when I execute it in IG in real market it still open position even after the loss happens. I am not sure what I am missing here?
Please note the code works when I am in positive and will not open new position after hitting 350. Could it be because of negative number in the strategy profit somehow mess up the formula?
This is my code:
If time=100000 then
MyProfit=STRATEGYPROFIT[0]
endif
if time>100000 and time <150000 and countoflongshares<90 and range[1]<14 and countofshortshares<90 and Strategyprofit[0]>MyProfit-200 and Strategyprofit[0]<MyProfit+350
then ……..
06/07/2022 at 10:11 AM #19483006/07/2022 at 10:13 AM #194831You have to use a variable as a signal that you don’t want to trade any longer that day (I will use TradeOK, setting to 1 at the beginning of each day), as soon as your strategy detects a loss of X, it will set TradedOK to 0. Your strategy will have to use TradeOK to tell whether trading or not:
1234567891011ONCE TradeOK = 1ONCE MyLimit = 200IF InstraDayBarIndex = 0 THENTradeOK = 1ENDIFIF (StrategyProfit[1] - StrategyProfit) >= MyLimit THENTradeOK = 0ENDIFIF MyLongConditions AND TradeOK THENBUY AT MARKETENDIF06/07/2022 at 10:39 AM #19483506/07/2022 at 10:53 AM #194838I have no idea without testing the complete code used.
06/07/2022 at 11:00 AM #194840since I want to look at the whole day performance , should I change your code to the below to not only check with the last bar but for the whole day from morning:
ONCE TradeOK = 1
ONCE MyLimit = 200
IF time = 100000 THEN
TradeOK = 1
Myprofit=strategyprofit
ENDIF
IF (Myprofit- strategyprofit) >= MyLimit THEN
TradeOK = 0
ENDIF06/07/2022 at 11:34 AM #194845Also will this still work if your strategy starts in negative. What I noticed is that if my total strategy profit is positive then next day the code works and when I have lost it stops but when the strategy was already in negative from last day the code somehow can’t calculate the negative minus negative and stop working
06/07/2022 at 1:20 PM #194848Try replacing line 6 with:
1IF (abs(StrategyProfit - StrategyProfit[1]) >= MyLimit) and (StrategyProfit < StrategyProfit[1]) THEN06/07/2022 at 2:42 PM #194855Thanks, but I need the strategy profit be calculated for the total of positions from 10:00 am. In your code if one of the positions closes in negative the strategy will stop because it will always compare the current bar with the last bar not the total strategyprofit from 10:00 am
06/07/2022 at 5:03 PM #194861You code above works fine for me. Why don’t you think it’s correct?
Try appending some GRAPH instructions to monitor data candle by candle:
1234567891011121314151617ONCE TradeOK = 1ONCE MyLimit = 200IF time = 100000 THENTradeOK = 1Myprofit=strategyprofitENDIFIF (Myprofit- strategyprofit) >= MyLimit THENTradeOK = 0ENDIFif average[20] crosses over average[200] and not onmarket thenbuy at marketendifset target pprofit 200set stop ploss 50graph MyProfit coloured(255,0,0,255)graph StrategyProfit coloured(0,255,0,255)graph Myprofit- strategyprofit1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on