PHP Code:
function main(OvernightLogic,UserTime,StartTime,EndTime,LineLen,Stop,Lv1,Lv2,Lv3,Lv4,CloseAllTime,TodayOnly,plotPrice,PriceOffset,TrdSz1,TrdSz2,TrdSz3,TrdSz4,MaxClip)
{
var xOpen = LineTag = null;
if(TodayOnly) LineTag = 105;
else LineTag = gID();
if(isMonthly() || isWeekly() || isDaily()) return;
var barDate = getValue("time");
var dayOfWeek = barDate.getDay();
if (dayOfWeek == 0) return;
if((hour(0)*100)+minute(0)>=UserTime && bInit == false)
{
nPrice = open(0);
drawLineRelative( 0, nPrice+Lv1, LineLen, nPrice+Lv1, PS_DOT, 1, Color.maroon, "Up"+LineTag );
drawLineRelative( 0, nPrice+Lv2, LineLen, nPrice+Lv2, PS_DOT, 1, Color.green, "Up1"+LineTag );
drawLineRelative( 0, nPrice+Lv3, LineLen, nPrice+Lv3, PS_DOT, 1, Color.red, "Up2"+LineTag );
drawLineRelative( 0, nPrice+Lv4, LineLen, nPrice+Lv4, PS_DOT, 2, Color.red, "Up3"+LineTag );
drawLineRelative( 0, nPrice-Lv1, LineLen, nPrice-Lv1, PS_DOT, 1, Color.maroon, "Dwn1"+LineTag );
drawLineRelative( 0, nPrice-Lv2, LineLen, nPrice-Lv2, PS_DOT, 1, Color.green, "Dwn2"+LineTag );
drawLineRelative( 0, nPrice-Lv3, LineLen, nPrice-Lv3, PS_DOT, 1, Color.red, "Dwn3"+LineTag );
drawLineRelative( 0, nPrice-Lv4, LineLen, nPrice-Lv4, PS_DOT, 2, Color.red, "Dwn4"+LineTag );
drawLineRelative( 0, nPrice, LineLen, nPrice, PS_SOLID, 1, Color.blue, "OpenMid"+LineTag );
bInit = true;
}
if(plotPrice.indexOf("Open")!=-1) drawTextRelative(PriceOffset, nPrice, nPrice+0, Color.blue, null, Text.BOLD | Text.LEFT | Text.VCENTER, null, 10, "TimeP_A");
if(plotPrice.indexOf("Res1")!=-1) drawTextRelative(PriceOffset, nPrice+Lv1, nPrice+Lv1, Color.maroon, null, Text.BOLD | Text.LEFT | Text.VCENTER, null, 10, "TimeP_H");
if(plotPrice.indexOf("Res2")!=-1) drawTextRelative(PriceOffset, nPrice+Lv2, nPrice+Lv2, Color.green, null, Text.BOLD | Text.LEFT | Text.VCENTER, null, 10, "TimeP_K");
if(plotPrice.indexOf("Res3")!=-1) drawTextRelative(PriceOffset, nPrice+Lv3, nPrice+Lv3, Color.red, null, Text.BOLD | Text.LEFT | Text.VCENTER, null, 10, "TimeP_L");
if(plotPrice.indexOf("Res4")!=-1) drawTextRelative(PriceOffset, nPrice+Lv4, nPrice+Lv4, Color.red, null, Text.BOLD | Text.LEFT | Text.VCENTER, null, 10, "TimeP_M");
if(plotPrice.indexOf("Sup1")!=-1) drawTextRelative(PriceOffset, nPrice-Lv1, nPrice-Lv1, Color.maroon, null, Text.BOLD | Text.LEFT | Text.VCENTER, null, 10, "TimeP_N");
if(plotPrice.indexOf("Sup2")!=-1) drawTextRelative(PriceOffset, nPrice-Lv2, nPrice-Lv2, Color.green, null, Text.BOLD | Text.LEFT | Text.VCENTER, null, 10, "TimeP_O");
if(plotPrice.indexOf("Sup3")!=-1) drawTextRelative(PriceOffset, nPrice-Lv3, nPrice-Lv3, Color.red, null, Text.BOLD | Text.LEFT | Text.VCENTER, null, 10, "TimeP_P");
if(plotPrice.indexOf("Sup4")!=-1) drawTextRelative(PriceOffset, nPrice-Lv4, nPrice-Lv4, Color.red, null, Text.BOLD | Text.LEFT | Text.VCENTER, null, 10, "TimeP_Q");
if (getCurrentBarIndex() == 0) return
var nPosSize = Strategy.getPositionSize();
if(EndTime > CloseAllTime) return;
// Daily Variable Reset and follow on if overnight
if (day(0)!= day(-1)) {
if (Strategy.isInTrade()) {
bYLong1 = bLong1;
bYLong2 = bLong2;
bYLong3 = bLong3;
bYLong4 = bLong4;
bYShort1 = bShort1;
bYShort2 = bShort2;
bYShort3 = bShort3;
bYShort4 = bShort4;
nYPrice = nPrice;
}
bLong1 = false;
bLong2 = false;
bLong3 = false;
bLong4 = false;
bShort1 = false;
bShort2 = false;
bShort3 = false;
bShort4 = false;
bExitFlag = false;
bInit = false;
}
if((hour(0)*100)+minute(0)< StartTime) return;
//Overnight exit logic
if(OvernightLogic){
if (Strategy.isShort() == true)
//if (bYShort1 == true || bYShort2 == true || bYShort3 == true || bYShort4 == true)
{
if (bYShort1 == true && bYShort2 == false && bYShort3 == false && bYShort4 == false)
{
if (low(0)< nYPrice)
{
nOExitPrice = nYPrice;
Strategy.doCover("Overnight Exit S1 Signal", Strategy.LIMIT, Strategy.THISBAR, Strategy.ALL, nOExitPrice);
drawShape(Shape.CIRCLE, BelowBar2, Color.green);
bYShort1 = false; bYShort2 = false; bYShort3 = false; bYShort4 = false;
}
}
if (bYShort1 == true && bYShort2 == true && bYShort3 == false && bYShort4 == false)
{
if (low(0)< nYPrice+Lv1)
{
nOExitPrice = nYPrice+Lv1;
Strategy.doCover("Overnight Exit S2 Signal", Strategy.LIMIT, Strategy.THISBAR, Strategy.ALL, nOExitPrice);
drawShape(Shape.CIRCLE, BelowBar2, Color.green);
bYShort1 = false; bYShort2 = false; bYShort3 = false; bYShort4 = false;
}
}
if (bYShort1 == true && bYShort2 == true && bYShort3 == true && bYShort4 == false)
{
if (low(0)< nYPrice+Lv2)
{
nOExitPrice = nYPrice+Lv2;
Strategy.doCover("Overnight Exit S3 Signal", Strategy.LIMIT, Strategy.THISBAR, Strategy.ALL, nOExitPrice);
drawShape(Shape.CIRCLE, BelowBar2, Color.green);
bYShort1 = false; bYShort2 = false; bYShort3 = false; bYShort4 = false;
}
}
if (bYShort1 == true && bYShort2 == true && bYShort3 == true && bYShort4 == true)
{
if (low(0)< nYPrice+Lv3)
{
nOExitPrice = nYPrice+Lv3;
Strategy.doCover("Overnight Exit S4 Signal", Strategy.LIMIT, Strategy.THISBAR, Strategy.ALL, nOExitPrice);
drawShape(Shape.CIRCLE, BelowBar2, Color.green);
bYShort1 = false; bYShort2 = false; bYShort3 = false; bYShort4 = false;
}
}
} else if (Strategy.isLong() == true)
//else if (bYLong1 == true || bYLong2 == true || bYLong3 == true || bYLong4 == true)
{
if (bYLong1 == true && bYLong2 == false && bYLong3 == false && bYLong4 == false)
{
if (high(0)> nYPrice)
{
nOExitPrice = nYPrice;
Strategy.doSell("Overnight Exit L1 Signal", Strategy.LIMIT, Strategy.THISBAR, Strategy.ALL, nOExitPrice);
drawShape(Shape.CIRCLE, AboveBar2, Color.green);
bYLong1 = false; bYLong2 = false; bYLong3 = false; bYLong4 = false;
}
}
if (bYLong1 == true && bYLong2 == true && bYLong3 == false && bYLong4 == false)
{
if (high(0)> nYPrice-Lv1)
{
nOExitPrice = nYPrice-Lv1;
Strategy.doSell("Overnight Exit L2 Signal", Strategy.LIMIT, Strategy.THISBAR, Strategy.ALL, nOExitPrice);
drawShape(Shape.CIRCLE, AboveBar2, Color.green);
bYLong1 = false; bYLong2 = false; bYLong3 = false; bYLong4 = false;
}
}
if (bYLong1 == true && bYLong2 == true && bYLong3 == true && bYLong4 == false)
{
if (high(0)> nYPrice-Lv2)
{
nOExitPrice = nYPrice-Lv2;
Strategy.doSell("Overnight Exit L3 Signal", Strategy.LIMIT, Strategy.THISBAR, Strategy.ALL, nOExitPrice);
drawShape(Shape.CIRCLE, AboveBar2, Color.green);
bYLong1 = false; bYLong2 = false; bYLong3 = false; bYLong4 = false;
}
}
if (bYLong1 == true && bYLong2 == true && bYLong3 == true && bYLong4 == true)
{
if (high(0)> nYPrice-Lv3)
{
nOExitPrice = nYPrice-Lv3;
Strategy.doSell("Overnight Exit L4 Signal", Strategy.LIMIT, Strategy.THISBAR, Strategy.ALL, nOExitPrice);
drawShape(Shape.CIRCLE, AboveBar2, Color.green);
bYLong1 = false; bYLong2 = false; bYLong3 = false; bYLong4 = false;
}
}
}
}
Comment