multiple events on a single bar – multitimeframe?
Forums › ProRealTime English forum › ProOrder support › multiple events on a single bar – multitimeframe?
- This topic has 3 replies, 2 voices, and was last updated 6 years ago by robertogozzi.
Tagged: mtf, multi timeframe, single bar
-
-
10/03/2018 at 11:11 AM #81836
Hi there
I wrote a simple code that takes the high/low of the market at close time and sets a buy/sell orders.
The buy/sell orders should only be called once per day.
I used an hourly time frame but I see that sometimes the orders are called more than once a day. It happens when the order was triggered and successful on the same bar.
So on the next bar there was no time to set a flag to state that the order was already ONMARKET to prevent it from going in again.
If I move the time frame to 1 second or even 1 minute this problem will probably not occur or occur less often but then I would not have access to enough historical data.
I am attaching this simple code snippet.
Is this a multiframe issue? is there any simple solution for this?
Any advice would be welcomed
Thanks in advance
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354DEFPARAM CumulateOrders = falseDEFPARAM FLATBefore = 220000DEFPARAM FLATAfter = 090000ONCE EndOfMarketTime = 220000ONCE CutOffTime = 09000ONCE WasInMarketFlag=0ONCE StopLoss=50ONCE StopLimit=50ONCE StakeSize=10ONCE EntryBuffer=10ONCE LongTriggered = 0ONCE ShortTriggered = 0ONCE State=100//GRAPH MyBuyprice//GRAPH MySellpriceGRAPH State//for every barIF ONMARKET THENWasInMarketFlag=1ENDIF//if time is EndOfMarketTime - reset all states for new day and set buy/sellIF time = EndOfMarketTime THENMyBuyprice = DHIGH(0)+EntryBufferMySellprice= DLOW(0)-EntryBufferStopLoss = MyBuyprice - MySellpriceState=1WasInMarketFlag=0ENDIF//if between EndOfMarketTime && CutOffTime -> if WasInMarketFlag is false - reset bar for buy/sellIF WasInMarketFlag = 0 THENIF LongTriggered=0 THEN //if longBUY StakeSize CONTRACTS AT MyBuyprice stopState=3ENDIFIF ShortTriggered=0 THENSELLSHORT StakeSize CONTRACTS AT MySellprice stopState=4ENDIFSET STOP LOSS StopLossSET TARGET PROFIT StopLimitENDIF//if time is CutOffTime - stop all markets (if ONMARKET)IF time >= CutOffTime AND WasInMarketFlag>0 THENIF LONGONMARKET THEN //TERMINATE TRADE AT END OF DAYSELL AT MARKETELSIF SHORTONMARKET THENEXITSHORT AT MARKETENDIFENDIF10/03/2018 at 11:49 AM #81838This is a version supporting MTF (I only have tested it for syntax errors):
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566DEFPARAM CumulateOrders = falseDEFPARAM FLATBefore = 220000DEFPARAM FLATAfter = 090000TIMEFRAME (1 hour,updateonclose)ONCE EndOfMarketTime = 220000ONCE CutOffTime = 090000 // ---> I added one more ZERO (it was 00:90:00 in your code)ONCE StopLoss=50ONCE StopLimit=50ONCE StakeSize=10ONCE EntryBuffer=10ONCE LongTriggered = 0ONCE ShortTriggered = 0ONCE State=100//GRAPH MyBuyprice//GRAPH MySellpriceGRAPH State//if time is EndOfMarketTime - reset all states for new day and set buy/sellIF time = EndOfMarketTime THENMyBuyprice = DHIGH(0)+EntryBufferMySellprice= DLOW(0)-EntryBufferStopLoss = MyBuyprice - MySellpriceState=1ENDIF//if between EndOfMarketTime && CutOffTime -> if WasInMarketFlag is false - reset bar for buy/sellIF WasInMarketFlag = 0 THENIF LongTriggered=0 THEN //if longBUY StakeSize CONTRACTS AT MyBuyprice stopState=3ENDIFIF ShortTriggered=0 THENSELLSHORT StakeSize CONTRACTS AT MySellprice stopState=4ENDIFSET STOP LOSS StopLossSET TARGET PROFIT StopLimitENDIF//////////////////////////////////////////////////////////////////////////TIMEFRAME (default)ONCE WasInMarketFlag=0ONCE IamLong =0ONCE IamShort =0IF IntraDayBarIndex = 0 THENWasInMarketFlag=0IamLong =0IamShort =0ENDIFIF time = EndOfMarketTime THENWasInMarketFlag=0ENDIF//if time is CutOffTime - stop all markets (if ONMARKET)IF time >= CutOffTime AND WasInMarketFlag>0 THENIF LONGONMARKET THEN //TERMINATE TRADE AT END OF DAYSELL AT MARKETELSIF SHORTONMARKET THENEXITSHORT AT MARKETENDIFENDIFIF WasInMarketFlag = 0 THENIamLong = LongOnMarketIamShort = ShortOnMarketWasInMarketFlag = IamLong OR IamShortENDIFThis will set WasInMarketFlag once in a 1-Minute TF and will be cleared each new day, so your 1-hour TF will not enter any longer for the rest of the trading day.
You will have less history.
If you don’t want to use MTF, then you would be able to know you were ONMARKET by checking STRATEGYPROFIT against its initial value saved at the beginning of each new day, something like:
123456789ONCE MyProfit = 0IF IntraDayBarIndex = 0 THENMyProfit = STRATEGYPROFITENDIFIF Not OnMarket AND Not OnMarket[1] THEN //no trades apparently since last barIF MyProfit <> STRATEGYPROFIT THENIwasLong = 1ENDIFENDIF10/03/2018 at 2:30 PM #81847You will have less history.
Thats great! thank you so much for this.
A question about the “less history” part.
Does it meant that MTF will always give the amount of data based on the lower time frame (so 1 sec time frame will have a few days even if the “main” code is based on daily)
Thanks again
Alan
10/03/2018 at 3:10 PM #81848Yes, the importance of the TF is just the opposite in MTF.
MTF recognizes the lowest TF as the main TF, the one used to launch your strategies on which BARINDEX, TRADEINDEX, INTRADAYBARINDEX, ONMARKET and so on… are updated.
All other TF’s must be multiple of the lower ones and variables can be created/changed only in one TF but read by any TF.
-
AuthorPosts
Find exclusive trading pro-tools on