Need a little help with my code of open breakout on SAF40
Forums › ProRealTime English forum › ProOrder support › Need a little help with my code of open breakout on SAF40
- This topic has 7 replies, 3 voices, and was last updated 6 years ago by
Lombard974.
-
-
08/27/2019 at 9:11 PM #105675
Hello Can someone please assist me with my code..
I run it on South african 40.. But I want it to open a buy or sell when it breaks the high or low of the 8:55 candle on 5 min chart.
I dont know how to change the code so that when price moves past the high or past the low it opens a order in that direction. So far all i could put together is this code below ehich opens a trade once the candle closes but i want it to place a trade in the candle thats busy breaking high or low not after close.Please help me change the code to be able to do it.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576DEFPARAM CumulateOrders = falseDEFPARAM FLATBefore = 084500 //09:00DEFPARAM FLATAfter = 210000 //21:00DEFPARAM PreLoadBars = 2000ONCE nLots = 15ONCE MaxPrice = 999999ONCE MinPrice = 0starttime = 090000SET STOP LOSS 150IF time = starttime THENMaxPrice = highest[1](high) //Il massimo/minimo delle ultime 12 barreMinPrice = lowest[1](low) // (ogni ora = 12 barre da 5 minuti)ENDIF//************************************************************************// trailing stop functiontrailingstart = 20 //5 trailing will start @trailinstart points profittrailingstep = 60 //5 trailing step to move the "stoploss"////reset the stoploss valueIF NOT ONMARKET THENnewSL=0ENDIF//manage long positionsIF LONGONMARKET THEN//first move (breakeven)IF newSL=0 AND close-tradeprice(1)>=trailingstart*pipsize THENnewSL = tradeprice(1)+trailingstep*pipsizeENDIF//next movesIF newSL>0 AND close-newSL>=trailingstep*pipsize THENnewSL = newSL+trailingstep*pipsizeENDIFENDIF//manage short positionsIF SHORTONMARKET THEN//first move (breakeven)IF newSL=0 AND tradeprice(1)-close>=trailingstart*pipsize THENnewSL = tradeprice(1)-trailingstep*pipsizeENDIF//next movesIF newSL>0 AND newSL-close>=trailingstep*pipsize THENnewSL = newSL-trailingstep*pipsizeENDIFENDIF//stop order to exit the positionsIF newSL>0 THENSELL AT newSL STOPEXITSHORT AT newSL STOPENDIF//************************************************************************// LONGa1 = close > MaxPriceIF a1 THENBuy nLots CONTRACT AT MARKETMaxPrice = 999999MinPrice = 0ENDIF// SHORTb1 = close < MinPriceIF b1 THENSellshort nLots CONTRACT AT MARKETMaxPrice = 999999MinPrice = 0ENDIFif countofposition = 1 thenbuy 1 contract at tradeprice + 50 stopendifif countofposition = -1 thensellshort 1 contract at tradeprice - 50 stopendif08/27/2019 at 11:34 PM #105690Replace lines 58 and 66 with pending orders, instead of at-market orders:
1Buy nLots CONTRACT AT MaxPrice STOP1Sellshort nLots CONTRACT AT MinPrice STOPIn this case you won’t even need lines 56-57, 59-61, 64-65 and 67-69.
08/29/2019 at 7:40 AM #105793Hi Roberto
Thanks for the help.. Now it buying at the right place but It keeps on placing orders through the day. I just want it to do on 1 trade per day.. Just the 9 O clock trade en when it closes it must do nothing for the rest of the day. Can you help me with this?
Thanks
08/29/2019 at 8:17 AM #105795At line 10 add:
1234IF OnMarket THENMaxPrice = -1MinPrice = -1ENDIFThis should do, since no trade will ever enter at a negative price. Next morning, AT STARTTIME new values will be set to start trading again.
08/29/2019 at 8:52 AM #105797You don’t say what time frame you are running this on. In one of your other similar topics you were asking for one pending order to be cancelled if the other one is filled. In the code you have posted here are you aware that if you run it on a say a 15 minute time frame then you will have both orders on the market at the same time and if one is filled the other one will still be on the market until the current fifteen minute bar closes? This means that at volatile times you could open a long and then have it close with a short order fill before the fifteen minute candle closes.
08/29/2019 at 9:50 AM #105809With that SL & TP it’s quite difficult that an order opens and closes on the same bar.
08/29/2019 at 10:52 AM #105815My comments weren’t really regarding TP and SL but I now see that I misread the code and it is actually only placing one pending order at a time and not the two that I thought it was. Totally my mistake for mixing up topics by Lombard974.
08/29/2019 at 12:32 PM #105823Thank you guys for the reply.. The code I put together here was a mix of a few forums.. I am running it on 5 min time frame.. I dont want it to place 2 pending orders anymore just open a trade when 5 min candle breaks the high or low at 8:55. The code above opens a trade but waits for the close of the first 5min candle 9:05. But thats sometimes a little late.. some trades on SAF40 I close manually 9:02 because price moved fast.. So this is what I am aiming for- High low break of 8:55 candle when market opens at 9:00. Then it must place no other trades- So far the code and trailing works well but if i can get it to activate a trade before the 9:05 candle closes the profit potential is allot higher.
I will try the above suggestions.Thanks
-
AuthorPosts
Find exclusive trading pro-tools on