HI,
I’m trying to trade between specified time and limit the number of trades (2).
I ran the test it will only trade once, will not trade up to twice a day everyday.
Can you please help with my code?
Thanks in Advance:)
Here is my code:
// Trading time: 11pm to 530am
DEFPARAM FLATBEFORE = 230000
DEFPARAM FLATAFTER = 052500
ONCE start = 230000
// limiting # of trades
IF Time = start THEN
TradeCount = 0
ENDIF
a = MACD[12,26,9](close)
b = SmoothedStochastic[14,3](close)
c = Average[24](close)
// Conditions to enter long positions
IF NOT LongOnMarket AND time>=start AND TradeCount<3 AND a>7 AND b>20 AND close>c THEN
BUY 1 LOT AT MARKET
TradeCount = TradeCount + 1
ENDIF
//
// Conditions to exit long positions
If LongOnMarket AND close<c THEN
SELL AT MARKET
ENDIF
// Conditions to enter short positions
IF NOT ShortOnMarket AND time>=start AND TradeCount<3 AND a<-7 AND b<80 AND close<c THEN
SELLSHORT 1 LOT AT MARKET
TradeCount=TradeCount+1
ENDIF
// Conditions to exit short positions
IF ShortOnMarket AND close>c THEN
EXITSHORT AT MARKET
ENDIF
// Stops and targets : Enter your protection stops and profit targets here
I do not see the problem at first read. Did you try to debug the “TradeCount” variables with a GRAPH?
GRAPH TradeCount
You’ll find it easy to debug with this line in your code, to see if the trade count is well incrementing.
I think you should decrement by 1 after/before lines 24 and 35 (TradeCount = TradeCount - 1).
But I did not test it.