Job finished
Specification
I would like to convert this simple pinescript study into an expert advisor:
study("myStudy1",overlay=true, shorttitle="study1") boxp=input(5, "BOX LENGTH") LL = lowest(low,boxp) k1=highest(high,boxp) k2=highest(high,boxp-1) k3=highest(high,boxp-2) NH = valuewhen(high>k1[1],high,0) box1 =k3<k2 TopBox = valuewhen(barssince(high>k1[1])==boxp-2 and box1, NH, 0) BottomBox = valuewhen(barssince(high>k1[1])==boxp-2 and box1, LL, 0) plot(TopBox, linewidth=3, color=green, title="TBbox") plot(BottomBox, linewidth=3, color=red, title="BBbox")
The study looks like this:
SELL SIGNAL:
When price crosses the red line, open sell at market price
Stop loss is the GREEN line
Take profit target is 4:1 reward ratio, so will depend on the size of the stop loss
BUY SIGNAL:
When the high crosses the green line, open a buy at market price
Stop loss is the RED line
Take profit target is 4:1 reward ratio, so will depend on the size of the stop loss
LOT SIZE:
calculation based on percentage of account, for example if the user chooses 1% risk, then calculation needed to work out the lot size.
EXIT CONDITIONS:
If short, exit the trade anytime that price touches the GREEN line (similar to a trailing stop)
If long, exit the trade anytime that price touches the RED line (similar to a trailing stop)
GENERAL RULES:
Expert should ignore all existing trades without the magic number
No hedging - so if an opposite signal happens during a trade, the expert needs to close the trade first, then open a new trade in the opposite direction
The maximum open trades (opened from the expert advisor) should be 1 per market. While a trade is already open, the expert will ignore new signals in the same direction.
Trades need to alternate - once a sell trade closes, only a buy signal can open next. Once a buy trade closes, only a sell signal can open next etc.