Forums › ProRealTime English forum › ProOrder support › multiple events on a single bar – multitimeframe? › Reply To: multiple events on a single bar – multitimeframe?
10/03/2018 at 11:49 AM
#81838
This is a version supporting MTF (I only have tested it for syntax errors):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
DEFPARAM CumulateOrders = false DEFPARAM FLATBefore = 220000 DEFPARAM FLATAfter = 090000 TIMEFRAME (1 hour,updateonclose) ONCE EndOfMarketTime = 220000 ONCE CutOffTime = 090000 // ---> I added one more ZERO (it was 00:90:00 in your code) ONCE StopLoss=50 ONCE StopLimit=50 ONCE StakeSize=10 ONCE EntryBuffer=10 ONCE LongTriggered = 0 ONCE ShortTriggered = 0 ONCE State=100 //GRAPH MyBuyprice //GRAPH MySellprice GRAPH State //if time is EndOfMarketTime - reset all states for new day and set buy/sell IF time = EndOfMarketTime THEN MyBuyprice = DHIGH(0)+EntryBuffer MySellprice= DLOW(0)-EntryBuffer StopLoss = MyBuyprice - MySellprice State=1 ENDIF //if between EndOfMarketTime && CutOffTime -> if WasInMarketFlag is false - reset bar for buy/sell IF WasInMarketFlag = 0 THEN IF LongTriggered=0 THEN //if long BUY StakeSize CONTRACTS AT MyBuyprice stop State=3 ENDIF IF ShortTriggered=0 THEN SELLSHORT StakeSize CONTRACTS AT MySellprice stop State=4 ENDIF SET STOP LOSS StopLoss SET TARGET PROFIT StopLimit ENDIF ////////////////////////////////////////////////////////////////////////// TIMEFRAME (default) ONCE WasInMarketFlag=0 ONCE IamLong =0 ONCE IamShort =0 IF IntraDayBarIndex = 0 THEN WasInMarketFlag=0 IamLong =0 IamShort =0 ENDIF IF time = EndOfMarketTime THEN WasInMarketFlag=0 ENDIF //if time is CutOffTime - stop all markets (if ONMARKET) IF time >= CutOffTime AND WasInMarketFlag>0 THEN IF LONGONMARKET THEN //TERMINATE TRADE AT END OF DAY SELL AT MARKET ELSIF SHORTONMARKET THEN EXITSHORT AT MARKET ENDIF ENDIF IF WasInMarketFlag = 0 THEN IamLong = LongOnMarket IamShort = ShortOnMarket WasInMarketFlag = IamLong OR IamShort ENDIF |
This 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:
1 2 3 4 5 6 7 8 9 |
ONCE MyProfit = 0 IF IntraDayBarIndex = 0 THEN MyProfit = STRATEGYPROFIT ENDIF IF Not OnMarket AND Not OnMarket[1] THEN //no trades apparently since last bar IF MyProfit <> STRATEGYPROFIT THEN IwasLong = 1 ENDIF ENDIF |