Simple Coding Help - No Promise.

chintan786

Well-Known Member
Dear Coding Gurus, I need help to add below condition in existing strategy for Backtest purpose.
Condition = " No Trade signal will be considered between 1100 AM to 1245 PM".

I want to add given condition and wants to check how already running signal will hold with it.

Thanks in Advance
 
Dear Coding Gurus, I need help to add below condition in existing strategy for Backtest purpose.
Condition = " No Trade signal will be considered between 1100 AM to 1245 PM".

I want to add given condition and wants to check how already running signal will hold with it.

Thanks in Advance
Check if this helps

Code:
AND (TimeNum()<110000 AND TimeNum()> 124500)

.
 

checkmate7

Well-Known Member
Can anyone write a code for dynamic SL based on following:

Buy= <any condition>
Short=<any condition>
Sell=<reverse of buy>
Cover=<reverse of Short>

Required:

I need my SL to be fixed 1% at the start of buy/short but when price reaches 1% then half my qty is exited and SL changed to buy/short price
Now again when price increments by 1% then SL get changed to entry price+0.5%....
This will continue till exit condition met by Sell/Cover or SL hit

Also this 1%/0.5% should be configurable...


Is it possible???
 
Last edited:
please Convert the below code to AFL

study(title="VDUB_BINARY_PRO_3_V2", shorttitle="VDUB_BINARY_PRO_3_V2", overlay=true)
source = close
length = input(56, minval=1, title = "WMA Length")
atrlen = input(100, minval=1, title = "ATR Length")
mult1 = 2
mult2 = 3
ma = wma(source, length)
range = tr
rangema = wma(range, atrlen)

up1 = ma + rangema * mult1
up2 = ma + rangema * mult2

dn1 = ma - rangema * mult1
dn2 = ma - rangema * mult2

color1 = white
color2 = white

u4 = plot(up1, color = color1)
u8 = plot(up2, color = color2)

d4 = plot(dn1, color = color1)
d8 = plot(dn2, color = color2)

fill(u8, u4, color=#30628E, transp=80)
fill(d8, d4, color=#30628E, transp=80)
fill(d4, u4, color=#128E89, transp=80)

//Linear regression band
src = close
//Input
nlookback = input (defval = 20, minval = 1, title = "Number of Lookback")
scale = input(defval=1, title="scale of ATR")
nATR = input(defval = 14, title="ATR Parameter")

//Center band
periods=input(21, minval=1, title="MA Period")
pc = input(true, title="MA BAND")

hld = iff(close > sma(high,periods)[1], 1, iff(close<sma(low,periods)[1],-1, 0))
hlv = valuewhen(hld != 0, hld, 1)

hi = pc and hlv == -1 ? sma(high, periods) : na
lo = pc and hlv == 1 ? sma(low,periods) : na
plot(avg(sma(high,periods)+2.5*(sma(high,periods)-sma(low,periods)),sma(low,periods)-2.5*(sma(high,periods)-sma(low,periods))), color=red, style=line,linewidth=4)
plot(pc and sma(high, periods) ? sma(high, periods):na ,title="Swing High Plot", color=black,style=line, linewidth=1)
plot(pc and sma(low,periods) ? sma(low,periods) : na ,title="Swing Low Plot", color=black,style=line, linewidth=1)
//fill(hlv,hld,color=#1c86ee,transp=80)
//--------------------------------------------------------------------------------------------
// Base line_VX1
source2 = close
short = sma(close, 3)
long = sma(close, 13)
plot(short, color=red, linewidth=2)
plot(long, color=navy, linewidth=4)
plot(cross(long, short) ? long : na, style = circles, color=blue, linewidth = 9)
OutputSignal = long >= short ? 1 : 0
bgcolor(OutputSignal>0?red:gray, transp=100)
//=======================================================
//Vdub_Tetris_V2
LRG_Channel_TF_mins_D_W_M = input("30")
Range2 = input(1)

SELL = security(tickerid, LRG_Channel_TF_mins_D_W_M, highest(Range2))
BUY = security(tickerid, LRG_Channel_TF_mins_D_W_M, lowest(Range2))

HI = plot(SELL, color=SELL!=SELL[1]?na:red,linewidth=2 )
LO = plot(BUY, color=BUY!=BUY[1]?na:green,linewidth=2 )
fill(HI, LO, color=#E3CAF1, transp=100)
Hcon = high >= SELL
Lcon = low <= BUY

plotshape(Hcon, style=shape.triangledown, color=maroon, location=location.abovebar)
plotshape(Lcon, style=shape.triangleup, color=green, location=location.belowbar)
range2 = SELL-BUY
//--------------------------------------------------

SML_Channel_TF_mins_D_W_M = input('240')
M_HIGH = security(tickerid, SML_Channel_TF_mins_D_W_M, high)
M_LOW = security(tickerid, SML_Channel_TF_mins_D_W_M, low)
plot(M_HIGH, color=M_HIGH != M_HIGH[1] ?na:fuchsia, style=line, linewidth=2)
plot(M_LOW, color=M_LOW != M_LOW[1] ?na:fuchsia, style=line, linewidth=2)
//--------------------------------------------------
Zingzag_length = input(7)
hls = rma(hl2, Zingzag_length)
isRising = hls >= hls[1]

zigzag1 = isRising and not isRising[1] ? lowest(Zingzag_length) : not isRising and isRising[1] ? highest(Zingzag_length) : na
plot(zigzag1, color=black)

Zigzag2 = input(false)
zigzag = Hcon ? high : Lcon ? low : na
plot(not Zigzag2 ? na : zigzag, color=red, style=line, linewidth=3)

//=====================================================================//

thanks

Varadan
 
please Convert the below code to AFL

study(title="VDUB_BINARY_PRO_3_V2", shorttitle="VDUB_BINARY_PRO_3_V2", overlay=true)
source = close
length = input(56, minval=1, title = "WMA Length")
atrlen = input(100, minval=1, title = "ATR Length")
mult1 = 2
mult2 = 3
ma = wma(source, length)
range = tr
rangema = wma(range, atrlen)

up1 = ma + rangema * mult1
up2 = ma + rangema * mult2

dn1 = ma - rangema * mult1
dn2 = ma - rangema * mult2

color1 = white
color2 = white

u4 = plot(up1, color = color1)
u8 = plot(up2, color = color2)

d4 = plot(dn1, color = color1)
d8 = plot(dn2, color = color2)

fill(u8, u4, color=#30628E, transp=80)
fill(d8, d4, color=#30628E, transp=80)
fill(d4, u4, color=#128E89, transp=80)

//Linear regression band
src = close
//Input
nlookback = input (defval = 20, minval = 1, title = "Number of Lookback")
scale = input(defval=1, title="scale of ATR")
nATR = input(defval = 14, title="ATR Parameter")

//Center band
periods=input(21, minval=1, title="MA Period")
pc = input(true, title="MA BAND")

hld = iff(close > sma(high,periods)[1], 1, iff(close<sma(low,periods)[1],-1, 0))
hlv = valuewhen(hld != 0, hld, 1)

hi = pc and hlv == -1 ? sma(high, periods) : na
lo = pc and hlv == 1 ? sma(low,periods) : na
plot(avg(sma(high,periods)+2.5*(sma(high,periods)-sma(low,periods)),sma(low,periods)-2.5*(sma(high,periods)-sma(low,periods))), color=red, style=line,linewidth=4)
plot(pc and sma(high, periods) ? sma(high, periods):na ,title="Swing High Plot", color=black,style=line, linewidth=1)
plot(pc and sma(low,periods) ? sma(low,periods) : na ,title="Swing Low Plot", color=black,style=line, linewidth=1)
//fill(hlv,hld,color=#1c86ee,transp=80)
//--------------------------------------------------------------------------------------------
// Base line_VX1
source2 = close
short = sma(close, 3)
long = sma(close, 13)
plot(short, color=red, linewidth=2)
plot(long, color=navy, linewidth=4)
plot(cross(long, short) ? long : na, style = circles, color=blue, linewidth = 9)
OutputSignal = long >= short ? 1 : 0
bgcolor(OutputSignal>0?red:gray, transp=100)
//=======================================================
//Vdub_Tetris_V2
LRG_Channel_TF_mins_D_W_M = input("30")
Range2 = input(1)

SELL = security(tickerid, LRG_Channel_TF_mins_D_W_M, highest(Range2))
BUY = security(tickerid, LRG_Channel_TF_mins_D_W_M, lowest(Range2))

HI = plot(SELL, color=SELL!=SELL[1]?na:red,linewidth=2 )
LO = plot(BUY, color=BUY!=BUY[1]?na:green,linewidth=2 )
fill(HI, LO, color=#E3CAF1, transp=100)
Hcon = high >= SELL
Lcon = low <= BUY

plotshape(Hcon, style=shape.triangledown, color=maroon, location=location.abovebar)
plotshape(Lcon, style=shape.triangleup, color=green, location=location.belowbar)
range2 = SELL-BUY
//--------------------------------------------------

SML_Channel_TF_mins_D_W_M = input('240')
M_HIGH = security(tickerid, SML_Channel_TF_mins_D_W_M, high)
M_LOW = security(tickerid, SML_Channel_TF_mins_D_W_M, low)
plot(M_HIGH, color=M_HIGH != M_HIGH[1] ?na:fuchsia, style=line, linewidth=2)
plot(M_LOW, color=M_LOW != M_LOW[1] ?na:fuchsia, style=line, linewidth=2)
//--------------------------------------------------
Zingzag_length = input(7)
hls = rma(hl2, Zingzag_length)
isRising = hls >= hls[1]

zigzag1 = isRising and not isRising[1] ? lowest(Zingzag_length) : not isRising and isRising[1] ? highest(Zingzag_length) : na
plot(zigzag1, color=black)

Zigzag2 = input(false)
zigzag = Hcon ? high : Lcon ? low : na
plot(not Zigzag2 ? na : zigzag, color=red, style=line, linewidth=3)

//=====================================================================//

thanks

Varadan
tr is not defined
that is required.
 
Hello,

I need help with simple afl, Bollinger Band

_SECTION_BEGIN("BB1 eez");
SetOption("Maxopenpositions", 20);
SetPositionSize(5, spsPercentOfEquity);

FTT = 091500; // Trading start time
LTT = 150000; //Last trading time
Exit = 151500; //Exit time intraday

BT = BBandTop(C,20,2);
BB = BBandBot(C,20,2);

Buy= (BT) AND TimeNum() <= LTT AND TimeNum() >= FTT ;
Short = (BB) AND TimeNum() <= LTT AND TimeNum() >= FTT ;
Sell= TimeNum() >= Exit ;
Cover= TimeNum() >= Exit;

Buy = C>= BT AND TimeNum() <= LTT AND TimeNum() >= FTT;
Sell = C<= BB OR TimeNum() >= Exit;

Plot(BT, "Bollinger Top", colorGreen, styleLine, 0,0,0,0);
Plot(BB, "Bollinger Bottom", colorRed, styleLine, 0,0,0,0);

Buy = ExRem(Buy, Sell);
Sell = ExRem(Sell, Buy);

PlotShapes(Buy*shapeUpArrow, colorGreen, 0, L);
PlotShapes(Sell*shapeDownTriangle, colorRed, 0, H);

_SECTION_END();

above is simple buy and sell code.

What i wants to add further is.....

1) Buy signal must be triggered when price crosses the breakout candle high.
2) Like wise sell signal must be triggered when price croses the breakout candle low.

3) True breakout is only that which satisfy that, The candles open is below bband and close is above bband.
If there is gap up in price and full candle is above bband then it is not a breakout, Open price must be below upper band line for a buy breakout, same applies to downside breakout.


Kindly help me with this.

Thank you,

Vishal
 

Similar threads