Hi.
I am unfamiliar with coding and am still trying to learn PRT, and I have a problem with an algo that I am working on. My problem as follows:
When taking buy/sell orders, the algo will e.g take the buy order, and at a point sell at market when the sell criteria have been met. (and vice versa for sell orders)
The problem that arises is when the candles go into a small range, the algo continues to buy/sell contracts.
Is there a way of coding to prevent this from happening? e.g. Do not take a long for x bars after the long contract has been sold and the opposite for short orders?
Any help is appreciated
Regards
You need to count bars elapsed after a trade ended:
ONCE WaitBars = 10
ONCE TradeON = 1 //1=enable trading 0=disable trading
ONCE Count = 0 //tallies bars as they elapse after a trade exits
IF Count > 0 THEN
Count = Count + 1 //tally bar after bar
ENDIF
IF Not OnMarket AND OnMarket[1] THEN //as soon as a trade exists start tallying
Count = 1 //set counter to 1 to start tallying
TradeON = 0 //disable trading
ENDIF
IF Count > WaitBars THEN //after desired number of bars elapsed reenable trading
Count = 0 //clear counter
TradeON = 1 //enable trading
ENDIF
IF MyConditions AND Not OnMarket AND TradeON THEN //add TradeON to your conditions
BUY/SELLSHORT...
ENDIF
Thank you for the displayed code Robert, I have incorporated it into my algo. However it has a problem with the “TradeOn” instruction which in the error message states SYNTAX ERROR: THIS VARIABLE IS NOT USED IN THE CODE:TRADEON
Regards
Use it like I did in line 15.
Thanks Robert, It works great
Regards
richarjo – Please use topic titles that actually mean something to help others know what your topic is about. I have changed your topic title from ‘Code’ to something more meaningful. 🙂