Hi guys,
I would like to buy a contract after the first contract is x bars old and negative. So that I would have 2 contract in total. And after that, if the cumulated contracts are positive (lets say 10 pips), the system should sell them both.
Thanks for helping!
BarWait = 20
IF not LongOnMarket and (your conditions) then
BUY 1 contract at market
ENDIF
IF LongOnMarket and (your conditions) and BarIndex - TradeIndex >= BarWait and close < PositionPrice then
BUY 1 contract at market
ENDIF
IF LongOnMarket and close > PositionPrice + 10 then
Sell at Market
ENDIF
This should do what you want. Difficult to tell from the description whether you want to stop trading at two positions or not. This code will just keep on buying.
No problem. there was a minor typo in the first BUY line so I have corrected that.
You could also consider only re-entering if the market has fallen by a certain percentage with something like this:
PercDrop = 1.5
IF LongOnMarket and (your conditions) and BarIndex - TradeIndex >= BarWait and close < PositionPrice * (1 - (PercDrop/100)) then
BUY 1 contract at market
ENDIF
There are benefits and disadvantages to this. Less trades = less exposure but you may miss trades right at the bottom of the market meaning that price has to climb further before you are in profit.
Another possibility is to increase your position size by an amount relative to the amount that the market has dropped.
PositionSize = 1
IF LongOnMarket and (your conditions) and BarIndex - TradeIndex >= BarWait then
BUY PositionSize + (PositionSize * (((close / PositionPrice) * 100) - 100)) contracts at market
ENDIF
Just some ideas – nothing proven!