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:
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
// 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