Sunday, 17 May 2015

AutoTrade Control For NEST/NOW for Amibroker (AFL)

Collected :)






Title = " ";
_SECTION_BEGIN("RKR_AutoTrade1V00 ");

EnableRealTimeControl = ParamList("Enable Controls", "No|Yes", 0);
EnableStrategy = ParamList("Enable Strategy", "No|Yes", 0);
StrategyType = ParamList("StrategyType", "Long/Short|Long|Short", 0);
EnableAutoTrade = ParamList("Enable Autotrade", "No|Yes", 0);
BuyPriceSelection = ParamList("Buy Price", "Bid Price|Ask Price|LTP", 0);
SellPriceSelection = ParamList("Sell Price", "Ask Price|Bid Price|LTP", 0);
ProductType = ParamList("Product Type", "MIS|NRML", 0);
OrderType = ParamList("Order Type", "LIMIT|MARKET", 0);
ClientIdValue = ParamStr("Client Id", "CLIENTID");
LotQuantity = Param("Lot Quantity", 1000, 50, 100000, 10);  // Default Trade Qty.
X2 = Param("Button X Offset", 0, 0, 2000, 100);
Y2 = Param("Button Y Offset", 0, 0, 2000, 100);
X1 = Param("Button Size", 100, 100, 300, 50);
//ParamList("Written By", "Marketdelta");
//ParamList("e-mail ID", "Marketdeltainvestment@gmail.com");
Buy = 0;
Sell = 0;
Short = 0;
Cover = 0;

if(EnableStrategy == "Yes")
{


Buy = Cross(MACD(12, 26), Signal(12, 26, 9));
Sell = Cross(Signal(12, 26, 9), MACD(12, 26));

Short = Cross(Signal(12, 26, 9), MACD(12, 26));
Cover = Cross(MACD(12, 26), Signal(12, 26, 9));


}


if(EnableAutoTrade == "Yes" && EnableRealTimeControl == "Yes")
{
    if(StaticVarGetText("firstflagforNest")=="")
    {
        nestplus = Null;
        if(IsNull(nestplus))
        {
            nestplus = CreateStaticObject("Nest.PlusApi");
            nestplus.SetObjectName("RKRAutoTrade");
        }
        StaticVarSetText ("firstflagforNest","0", 1);
    }
   
}

X0 = 20;
Y0 = 10;
procedure DashBoard (Text, x1, y1, x2, y2, colorFrom, colorTo)
{
    GfxSetOverlayMode(0);
    GfxSelectFont("Segoe UI", 8.5, 500);
    GfxSetBkMode(1);
    GfxGradientRect(x1, y1, x2, y2, colorFrom, colorTo);
    GfxDrawText(Text, x1, y1, x2, y2, 32|0|4|16);
}
GfxSetTextColor(colorWhite);

DashBoard (" Strategy: " + EnableStrategy, X0, Y0, X0+150, Y0+13, colorGrey40, colorGrey40);
DashBoard (" Strategy Type: " + StrategyType, X0, Y0+13, X0+150, Y0+26, colorGrey40, colorGrey40);
DashBoard (" Auto Trade: " + EnableAutoTrade, X0, Y0+26, X0+150, Y0+38, colorGrey40, colorGrey40);
DashBoard (" Buy Price: " + BuyPriceSelection, X0, Y0+38, X0+150, Y0+50, colorGrey40, colorGrey40);
DashBoard (" Sell Price: " + SellPriceSelection, X0, Y0+50, X0+150, Y0+62, colorGrey40, colorGrey40);
DashBoard (" Product Type: " + ProductType, X0, Y0+62, X0+150, Y0+75, colorGrey40, colorGrey40);
DashBoard (" Order Type: " + OrderType, X0, Y0+75, X0+150, Y0+88, colorGrey40, colorGrey40);
DashBoard ("", X0+1, Y0+88, X0+149, Y0+89, colorRed, colorRed);
GfxSetTextColor(colorAqua);
DashBoard ("        Market Delta ", X0, Y0+89, X0+150, Y0+105, colorBlack, colorBlack);

X0 = 180;
Y0 = 10;
procedure DrawData (Text, x1, y1, x2, y2, colorFrom, colorTo)
{
    GfxSetOverlayMode(0);
    GfxSelectFont("Segoe UI", 8.5, 600);
    GfxSetBkMode(1);
    GfxGradientRect(x1, y1, x2, y2, colorFrom, colorTo);
    GfxDrawText(Text, x1, y1, x2, y2, 32|0|4|16);
}
GfxSetTextColor(colorWhite);
DrawData (" " + Name(), X0, Y0, X0+160, Y0+15, colorGrey40, colorGrey40);
DrawData (" " + Date(), X0+170, Y0, X0+260, Y0+15, colorGrey40, colorGrey40);
DrawData (" Open : " + Open, X0+275, Y0, X0+380, Y0+15, colorGrey40, colorGrey40);
DrawData (" Close : " + Close, X0+390, Y0, X0+500, Y0+15, colorGrey40, colorGrey40);
DrawData (" High : " + High, X0+510, Y0, X0+620, Y0+15, colorGrey40, colorGrey40);
DrawData (" Low : " + Low, X0+630, Y0, X0+740, Y0+15, colorGrey40, colorGrey40);
DrawData (" Volume : " + NumToStr(Volume,1,0), X0+750, Y0, X0+960, Y0+15, colorGrey40, colorGrey40);
DrawData (" % Change : " + NumToStr( (((C-O)*100)/O), 1.2, True), X0+980, Y0, X0+1080, Y0+15, colorGrey40, colorGrey40);

if(StaticVarGetText("firstflag")=="")
{
    StaticVarSet("OrderNo", 0);
   
    StaticVarSetText ("firstflag","0");
}

if(StaticVarGetText("firstflag"+Name())=="")
{
    StaticVarSet(("BuyIndex" + Name()), 0);
    StaticVarSet(("BuyCount" + Name()), 0);
    StaticVarSet(("BuyFlag"  + Name()), 0);
    StaticVarSet(("BuyPrice"  + Name()), 0);
    StaticVarSet(("BuyQty"  + Name()), 0);
   
    StaticVarSet(("SellIndex" + Name()), 0);
    StaticVarSet(("SellCount" + Name()), 0);
    StaticVarSet(("SellFlag"  + Name()), 0);
    StaticVarSet(("SellPrice"  + Name()), 0);
    StaticVarSet(("SellQty"  + Name()), 0);
   
    StaticVarSet(("ShortIndex" + Name()), 0);
    StaticVarSet(("ShortCount" + Name()), 0);
    StaticVarSet(("ShortFlag"  + Name()), 0);
    StaticVarSet(("ShortPrice"  + Name()), 0);
    StaticVarSet(("ShortQty"  + Name()), 0);
   
    StaticVarSet(("CoverIndex" + Name()), 0);
    StaticVarSet(("CoverCount" + Name()), 0);
    StaticVarSet(("CoverFlag"  + Name()), 0);
    StaticVarSet(("CoverPrice"  + Name()), 0);
    StaticVarSet(("CoverQty"  + Name()), 0);
   
    StaticVarSet("LTPSave" + Name(), 0);
    StaticVarSet("LTQSave" + Name(), 0);
    StaticVarSet("VolumeTemp" + Name(), 0);
    StaticVarSet("AskSave" + Name(), 0);
    StaticVarSet("BidSave" + Name(), 0);
   
    StaticVarSet("LastLTPColor" + Name(), colorGrey40);
    StaticVarSet("LastLTQColor" + Name(), colorGrey40);
    StaticVarSet("LastAskColor" + Name(), colorGrey40);
    StaticVarSet("LastBidColor" + Name(), colorGrey40);
   
    StaticVarSetText("firstflag"+Name(), "0");
}

CurrentAskPrice = LastValue(Aux1);
CurrentBidPrice = LastValue(Aux2);
CurrentTradedPrice = LastValue(C);
CurrentVolume = LastValue(Volume);

if(BuyPriceSelection == "Bid Price")
{
    BuyPriceValue = CurrentBidPrice;
}
else if(BuyPriceSelection == "Ask Price")
{
    BuyPriceValue = CurrentAskPrice;
}
else
{
    BuyPriceValue = CurrentTradedPrice;
}

if(SellPriceSelection == "Ask Price")
{
    SellPriceValue = CurrentAskPrice;
}
else if(SellPriceSelection == "Bid Price")
{
    SellPriceValue = CurrentBidPrice;
}
else
{
    SellPriceValue = CurrentTradedPrice;
}

LTPTemp = StaticVarGet("LTPSave" + Name());
LTQTemp = StaticVarGet("LTQSave" + Name());
VolumeTemp = StaticVarGet("VolumeTemp" + Name());
AskTemp = StaticVarGet("AskSave" + Name());
BidTemp = StaticVarGet("BidSave" + Name());

CurrentLTQ = (CurrentVolume - VolumeTemp);

if(CurrentLTQ < 0)
{
    CurrentLTQ = CurrentLTQ * -1;
}

if(CurrentLTQ == 0)
{
    CurrentLTQ = LTQTemp;
}

LTPColor = StaticVarGet("LastLTPColor" + Name());
LTQColor = StaticVarGet("LastLTQColor" + Name());
AskColor = StaticVarGet("LastAskColor" + Name());
BidColor = StaticVarGet("LastBidColor" + Name());


if(LTPTemp > CurrentTradedPrice)
{
    LTPColor = colorRed;
}
else if(LTPTemp < CurrentTradedPrice)
{
    LTPColor = colorGreen;
}

if(LTQTemp > CurrentLTQ)
{
    LTQColor = colorRed;
}
else if(LTQTemp < CurrentLTQ)
{
    LTQColor = colorGreen;
}

if(AskTemp > CurrentAskPrice)
{
    AskColor = colorRed;
}
else if(AskTemp < CurrentAskPrice)
{
    AskColor = colorGreen;
}

if(BidTemp > CurrentBidPrice)
{
    BidColor = colorRed;
}
else if(BidTemp < CurrentBidPrice)
{
    BidColor = colorGreen;
}

StaticVarSet("LastLTPColor" + Name(), LTPColor);
StaticVarSet("LastLTQColor" + Name(), LTQColor);
StaticVarSet("LastAskColor" + Name(), AskColor);
StaticVarSet("LastBidColor" + Name(), BidColor);

StaticVarSet("LTPSave" + Name(), CurrentTradedPrice);
StaticVarSet("LTQSave" + Name(), CurrentLTQ);
StaticVarSet("VolumeTemp" + Name(), CurrentVolume);
StaticVarSet("AskSave" + Name(), CurrentAskPrice);
StaticVarSet("BidSave" + Name(), CurrentBidPrice);


X0 = X2 + 20;
Y0 = Y2 + 120;
LBClick = GetCursorMouseButtons() == 9;    // Click
MouseX  = Nz(GetCursorXPosition(1));        //
MouseY  = Nz(GetCursorYPosition(1));        //

//NumPad0 = GetAsyncKeyState(96) < 0;
//NumPad4 = GetAsyncKeyState(100) < 0;
//NumPad5 = GetAsyncKeyState(101) < 0;
//NumPad7 = GetAsyncKeyState(103) < 0;
//NumPad8 = GetAsyncKeyState(104) < 0;

procedure DrawBut (Text, x1, y1, x2, y2, colorFrom, colorTo)
{
    GfxSetOverlayMode(0);
    GfxSelectFont("Segoe UI", 9, 700);
    GfxSetBkMode(1);
    GfxGradientRect(x1, y1, x2, y2, colorFrom, colorTo);
    GfxDrawText(Text, x1, y1, x2, y2, 32|1|4|16);
}
GfxSetTextColor(colorWhite);

if(EnableRealTimeControl == "Yes")
{

    DrawBut ("Buy", X0, Y0, X0+X1, Y0+30, colorGreen, colorGreen);
    CursorInBuyButton = MouseX >= X0 AND MouseX <= X0+X1 AND MouseY >= Y0 AND MouseY <= Y0+30;
    BuyButtonClick = CursorInBuyButton AND LBClick;
    if (BuyButtonClick || NumPad7 )
    {
        TempBuy = Buy;
        Buy = IIf((DateTime() == LastValue(DateTime())) || (TempBuy == True), True, False);
    }

    DrawBut ("Sell", X0, Y0+40, X0+X1, Y0+70, colorRed, colorRed);
    CursorInSellButton = MouseX >= X0 AND MouseX <= X0+X1 AND MouseY >= Y0+40 AND MouseY <= Y0+70;
    SellButtonClick = CursorInSellButton AND LBClick;
    if (SellButtonClick || NumPad8)
    {
        TempSell = Sell;
        Sell = IIf((DateTime() == LastValue(DateTime())) || (TempSell == True), True, False);
    }
   
    DrawBut ("Short", X0, Y0+80, X0+X1, Y0+110, colorOrange, colorOrange);
    CursorInShortButton = MouseX >= X0 AND MouseX <= X0+X1 AND MouseY >= Y0+80 AND MouseY <= Y0+110;
    ShortButtonClick = CursorInShortButton AND LBClick;
    if (ShortButtonClick || NumPad4)
    {
        TemShort = Short;
        Short = IIf((DateTime() == LastValue(DateTime())) || (TemShort == True), True, False);
    }

    DrawBut ("Cover", X0, Y0+120, X0+X1, Y0+150, colorTurquoise, colorTurquoise);
    CursorInCoverButton = MouseX >= X0 AND MouseX <= X0+X1 AND MouseY >= Y0+120 AND MouseY <= Y0+150;
    CoverButtonClick = CursorInCoverButton AND LBClick;
    if (CoverButtonClick || NumPad5)
    {
        TempCover = Cover;
        Cover = IIf((DateTime() == LastValue(DateTime())) || (TempCover == True), True, False);
    }

    DrawBut ("Clear Data", X0, Y0+160, X0+X1, Y0+190, colorGrey40, colorGrey40);
    CursorInClearButton = MouseX >= X0 AND MouseX <= X0+X1 AND MouseY >= Y0+160 AND MouseY <= Y0+190;
    ClearButtonClick = CursorInClearButton AND LBClick;
    if (ClearButtonClick || NumPad0 )
    {
        DrawBut("Clear", X0+X1+10, Y0, X0+X1+75, Y0+30,  colorGrey40, colorGrey40);

        StaticVarSetText("firstflag"+Name(), "");
    }
   
    TempBuy = IIf((DateTime() == LastValue(DateTime())) && (LastValue(Buy) == True), True, False);
    BuyTempData = StaticVarGet("BuyIndex" + Name());
    TempCount = StaticVarGet("BuyCount" + Name());
    BuyPrevTemp = 0;
    for(i = 0; i <= TempCount; i++)
    {
        BuyPrevTemp = BuyPrevTemp | (IIf(DateTime() == BuyTempData[i], True, False));
    }
    Buy = IIf(((BuyPrevTemp == True) || (TempBuy == True)), True, False);
   
   
    TempSell = IIf((DateTime() == LastValue(DateTime())) && (LastValue(Sell) == True), True, False);
    SellTempData = StaticVarGet("SellIndex" + Name());
    TempCount = StaticVarGet("SellCount" + Name());
    SellPrevTemp = 0;
    for(i = 0; i <= TempCount; i++)
    {
        SellPrevTemp = SellPrevTemp | (IIf(DateTime() == SellTempData[i], True, False));
    }
    TempCount = StaticVarGet("BuyCount" + Name());
    Sell = IIf((TempCount > 0) && ((SellPrevTemp == True) || (TempSell == True)), True, False);
   

    TempShort = IIf((DateTime() == LastValue(DateTime())) && (LastValue(Short) == True), True, False);
    ShortTempData = StaticVarGet("ShortIndex" + Name());
    TempCount = StaticVarGet("ShortCount" + Name());
    ShortPrevTemp = 0;
    for(i = 0; i <= TempCount; i++)
    {
        ShortPrevTemp = ShortPrevTemp | (IIf(DateTime() == ShortTempData[i], True, False));
    }
    Short = IIf(((ShortPrevTemp == True) || (TempShort == True)), True, False);
   

    TempCover = IIf((DateTime() == LastValue(DateTime())) && (LastValue(Cover) == True), True, False);
    CoverTempData = StaticVarGet("CoverIndex" + Name());
    TempCount = StaticVarGet("CoverCount" + Name());
    CoverPrevTemp = 0;
    for(i = 0; i <= TempCount; i++)
    {
        CoverPrevTemp = CoverPrevTemp | (IIf(DateTime() == CoverTempData[i], True, False));
    }
    TempCount = StaticVarGet("ShortCount" + Name());
    Cover = IIf((TempCount > 0) && ((CoverPrevTemp == True) || (TempCover == True)), True, False);
   
}

if(StrategyType == "Long")
{
    Short = 0;
    Cover = 0;
}
else if(StrategyType == "Short")
{
    Buy = 0;
    Sell = 0;
}

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

Short = ExRem( Short, Cover );
Cover = ExRem( Cover, Short );

Buyshape = Buy * shapeUpArrow;
SellShape = Sell * shapeDownArrow;
PlotShapes( Buyshape, colorBrightGreen, 0, Low );
PlotShapes( SellShape, colorRed, 0, High );

Shortshape = Short * shapeDownArrow;
CoverShape = Cover * shapeUpArrow;
PlotShapes( Shortshape, colorOrange, 0, High, -30);
PlotShapes( CoverShape, colorTurquoise, 0, Low, -30 );

GraphXSpace = 5;
   
   
if(EnableRealTimeControl == "Yes")
{
    if((LastValue(Buy) == True) && (StaticVarGet(("BuyFlag" + Name())) != LastValue(DateTime())))
    {
        StaticVarSet(("BuyFlag" + Name()), LastValue(DateTime()));
        DrawBut("Buy", X0+X1+10, Y0, X0+X1+75, Y0+30,  colorGrey40, colorGrey40);
        TempCount = StaticVarGet("BuyCount" + Name());
        TempIndex = StaticVarGet("BuyIndex" + Name());
        TempPrice = StaticVarGet("BuyPrice"  + Name());
        TempQty = StaticVarGet("BuyQty"  + Name());
        TempIndex[TempCount] = LastValue(DateTime());
        TempPrice[TempCount] = BuyPriceValue;
        TempQty[TempCount] = LotQuantity;
        TempCount++;
        StaticVarSet("BuyCount" + Name(), TempCount);
        StaticVarSet(("BuyIndex" + Name()), TempIndex);
        StaticVarSet(("BuyPrice" + Name()), TempPrice);
        StaticVarSet(("BuyQty" + Name()), TempQty);
       
        if(EnableAutoTrade == "Yes")
        {
            LastOrderNo = StaticVarGet("OrderNo");
            LastOrderNo++;
            StaticVarSet("OrderNo", LastOrderNo);
            TempOrderNo = ClientIdValue + NumToStr(Now(3),1,0) + "00" + LastOrderNo;
            TempName = Name() + "-EQ";
            nestplus.PlaceOrder("BUY", TempOrderNo, "NSE", TempName, "DAY", OrderType, LotQuantity, BuyPriceValue, 0.0, 0, ProductType, ClientIdValue);
        }
    }

    if((LastValue(Sell) == True) && (StaticVarGet(("SellFlag" + Name())) != LastValue(DateTime())))
    {
        StaticVarSet(("SellFlag" + Name()), LastValue(DateTime()));
        DrawBut("Sell", X0+X1+10, Y0, X0+X1+75, Y0+30,  colorGrey40, colorGrey40);
        TempCount = StaticVarGet("SellCount" + Name());
        TempIndex = StaticVarGet("SellIndex" + Name());
        TempPrice = StaticVarGet("SellPrice"  + Name());
        TempQty = StaticVarGet("SellQty"  + Name());
        TempIndex[TempCount] = LastValue(DateTime());
        TempPrice[TempCount] = SellPriceValue;
        TempQty[TempCount] = LotQuantity;
        TempCount++;
        StaticVarSet("SellCount" + Name(), TempCount);
        StaticVarSet(("SellIndex" + Name()), TempIndex);
        StaticVarSet(("SellPrice" + Name()), TempPrice);
        StaticVarSet(("SellQty" + Name()), TempQty);
       
        if(EnableAutoTrade == "Yes")
        {
            LastOrderNo = StaticVarGet("OrderNo");
            LastOrderNo++;
            StaticVarSet("OrderNo", LastOrderNo, 1);
            TempOrderNo = ClientIdValue + NumToStr(Now(3),1,0) + "00" + LastOrderNo;
            TempName = Name() + "-EQ";
            nestplus.PlaceOrder("SELL", TempOrderNo, "NSE", TempName, "DAY", OrderType, LotQuantity, SellPriceValue, 0.0, 0, ProductType, ClientIdValue);
        }
    }
   
    if((LastValue(Short) == True) && (StaticVarGet(("ShortFlag" + Name())) != LastValue(DateTime())))
    {
        StaticVarSet(("ShortFlag" + Name()), LastValue(DateTime()));
        DrawBut("Short", X0+X1+10, Y0, X0+X1+75, Y0+30,  colorGrey40, colorGrey40);
        TempCount = StaticVarGet("ShortCount" + Name());
        TempIndex = StaticVarGet("ShortIndex" + Name());
        TempPrice = StaticVarGet("ShortPrice"  + Name());
        TempQty = StaticVarGet("ShortQty"  + Name());
        TempIndex[TempCount] = LastValue(DateTime());
        TempPrice[TempCount] = SellPriceValue;
        TempQty[TempCount] = LotQuantity;
        TempCount++;
        StaticVarSet("ShortCount" + Name(), TempCount);
        StaticVarSet(("ShortIndex" + Name()), TempIndex);
        StaticVarSet(("ShortPrice" + Name()), TempPrice);
        StaticVarSet(("ShortQty" + Name()), TempQty);
       
        if(EnableAutoTrade == "Yes")
        {
            LastOrderNo = StaticVarGet("OrderNo");
            LastOrderNo++;
            StaticVarSet("OrderNo", LastOrderNo);
            TempOrderNo = ClientIdValue + NumToStr(Now(3),1,0) + "00" + LastOrderNo;
            TempName = Name() + "-EQ";
            nestplus.PlaceOrder("SELL", TempOrderNo, "NSE", TempName, "DAY", OrderType, LotQuantity, SellPriceValue, 0.0, 0, ProductType, ClientIdValue);
        }
    }

    if((LastValue(Cover) == True) && (StaticVarGet(("CoverFlag" + Name())) != LastValue(DateTime())))
    {
        StaticVarSet(("CoverFlag" + Name()), LastValue(DateTime()));
        DrawBut("Cover", X0+X1+10, Y0, X0+X1+75, Y0+30,  colorGrey40, colorGrey40);
        TempCount = StaticVarGet("CoverCount" + Name());
        TempIndex = StaticVarGet("CoverIndex" + Name());
        TempPrice = StaticVarGet("CoverPrice"  + Name());
        TempQty = StaticVarGet("CoverQty"  + Name());
        TempIndex[TempCount] = LastValue(DateTime());
        TempPrice[TempCount] = BuyPriceValue;
        TempQty[TempCount] = LotQuantity;
        TempCount++;
        StaticVarSet("CoverCount" + Name(), TempCount);
        StaticVarSet(("CoverIndex" + Name()), TempIndex);
        StaticVarSet(("CoverPrice" + Name()), TempPrice);
        StaticVarSet(("CoverQty" + Name()), TempQty);
       
        if(EnableAutoTrade == "Yes")
        {
            LastOrderNo = StaticVarGet("OrderNo");
            LastOrderNo++;
            StaticVarSet("OrderNo", LastOrderNo, 1);
            TempOrderNo = ClientIdValue + NumToStr(Now(3),1,0) + "00" + LastOrderNo;
            TempName = Name() + "-EQ";
            nestplus.PlaceOrder("BUY", TempOrderNo, "NSE", TempName, "DAY", OrderType, LotQuantity, BuyPriceValue, 0.0, 0, ProductType, ClientIdValue);
        }
    }
}
   
X0 = 180;
Y0 = 30;

if(EnableRealTimeControl == "Yes")
{
    TotPrice = 0;
    TotQty = 0;
    TotVal = 0;
    TempPriceArray = StaticVarGet("BuyPrice" + Name());
    TempQtyArray = StaticVarGet("BuyQty" + Name());
    TempCount = StaticVarGet("BuyCount" + Name());
    for(i = 0; i < TempCount; i++)
    {
        TotPrice = TotPrice + TempPriceArray[i];
        TotQty = TotQty + TempQtyArray[i];
        TotVal = TotVal + TempPriceArray[i] * TempQtyArray[i];
    }
    if(TempCount == 0)
    {
        AvgBuyPrice = 0;
        LastBuyPrice = 0;
        LastBuyQty = 0;
    }
    else
    {
        AvgBuyPrice = (TotPrice / TempCount);
        LastBuyPrice = TempPriceArray[(TempCount - 1)];
        LastBuyQty = NumToStr(TempQtyArray[(TempCount - 1)], 1, 0);
    }
    TotBuyQty = NumToStr(TotQty, 1, 0);
    NetBuyQty = TotQty;
    NetBuyValue = TotVal;
   
    TotPrice = 0;
    TotQty = 0;
    TotVal = 0;
    TempPriceArray = StaticVarGet("SellPrice" + Name());
    TempQtyArray = StaticVarGet("SellQty" + Name());
    TempCount = StaticVarGet("SellCount" + Name());
    for(i = 0; i < TempCount; i++)
    {
        TotPrice = TotPrice + TempPriceArray[i];
        TotQty = TotQty + TempQtyArray[i];
        TotVal = TotVal + TempPriceArray[i] * TempQtyArray[i];
    }
    if(TempCount == 0)
    {
        AvgSellPrice = 0;
        LastSellPrice = 0;
        LastSellQty = 0;
    }
    else
    {
        AvgSellPrice = (TotPrice / TempCount);
        LastSellPrice = TempPriceArray[(TempCount - 1)];
        LastSellQty = NumToStr(TempQtyArray[(TempCount - 1)], 1, 0);
    }
    TotSellQty = NumToStr(TotQty, 1, 0);
    NetSellQty = TotQty;
    NetSellValue = TotVal;
   
    TotPrice = 0;
    TotQty = 0;
    TotVal = 0;
    TempPriceArray = StaticVarGet("ShortPrice" + Name());
    TempQtyArray = StaticVarGet("ShortQty" + Name());
    TempCount = StaticVarGet("ShortCount" + Name());
    for(i = 0; i < TempCount; i++)
    {
        TotPrice = TotPrice + TempPriceArray[i];
        TotQty = TotQty + TempQtyArray[i];
        TotVal = TotVal + TempPriceArray[i] * TempQtyArray[i];
    }
    if(TempCount == 0)
    {
        AvgShortPrice = 0;
        LastShortPrice = 0;
        LastShortQty = 0;
    }
    else
    {
        AvgShortPrice = (TotPrice / TempCount);
        LastShortPrice = TempPriceArray[(TempCount - 1)];
        LastShortQty = NumToStr(TempQtyArray[(TempCount - 1)], 1, 0);
    }
    TotShortQty = NumToStr(TotQty, 1, 0);
    NetShortQty = TotQty;
    NetShortValue = TotVal;
   
    TotPrice = 0;
    TotQty = 0;
    TotVal = 0;
    TempPriceArray = StaticVarGet("CoverPrice" + Name());
    TempQtyArray = StaticVarGet("CoverQty" + Name());
    TempCount = StaticVarGet("CoverCount" + Name());
    for(i = 0; i < TempCount; i++)
    {
        TotPrice = TotPrice + TempPriceArray[i];
        TotQty = TotQty + TempQtyArray[i];
        TotVal = TotVal + TempPriceArray[i] * TempQtyArray[i];
    }
    if(TempCount == 0)
    {
        AvgCoverPrice = 0;
        LastCoverPrice = 0;
        LastCoverQty = 0;
    }
    else
    {
        AvgCoverPrice = (TotPrice / TempCount);
        LastCoverPrice = TempPriceArray[(TempCount - 1)];
        LastCoverQty = NumToStr(TempQtyArray[(TempCount - 1)], 1, 0);
    }
    TotCoverQty = NumToStr(TotQty, 1, 0);
    NetCoverQty = TotQty;
    NetCoverValue = TotVal;
   
    NetQty = NetSellQty - NetBuyQty + NetShortQty - NetCoverQty;
    NetValue = NetSellValue - NetBuyValue + NetShortValue - NetCoverValue;
   
    NetQuantityColor = colorGrey40;
    NetValueColor = colorGrey40;

    if(NetQty > 0)
    {
        NetQuantityColor = colorRed;
        NetValueColor = colorRed;
    }
    else if(NetQty < 0)
    {
        NetQuantityColor = colorGreen;
        NetValueColor = colorGreen;
    }
    else if(NetQty == 0)
    {
        if(NetValue > 0)
        {
            NetValueColor = colorGreen;
        }
        else if(NetValue < 0)
        {
            NetValueColor = colorRed;
        }
    }
   
    DrawData (" AvgBuyPr: " + AvgBuyPrice, X0, Y0, X0+150, Y0+15, colorGrey40, colorGrey40);
    DrawData (" TotBuyQty: " + TotBuyQty, X0+155 , Y0, X0+305, Y0+15, colorGrey40, colorGrey40);
    DrawData (" AvgSellPr: " + AvgSellPrice, X0+310, Y0, X0+460, Y0+15, colorGrey40, colorGrey40);
    DrawData (" TotSellQty: " + TotSellQty, X0+465, Y0, X0+615, Y0+15, colorGrey40, colorGrey40);
    DrawData (" AvgShortPr: " + AvgShortPrice, X0+620, Y0, X0+770, Y0+15, colorGrey40, colorGrey40);
    DrawData (" TotShortQty: " + TotShortQty, X0+775 , Y0, X0+925, Y0+15, colorGrey40, colorGrey40);
    DrawData (" AvgCoverPr: " + AvgCoverPrice, X0+930, Y0, X0+1080, Y0+15, colorGrey40, colorGrey40);
    DrawData (" TotCoverQty: " + TotCoverQty, X0+1085, Y0, X0+1235, Y0+15, colorGrey40, colorGrey40);
   
    Y0 = 50;
   
    DrawData (" LastBuyPr: " + LastBuyPrice, X0, Y0, X0+150, Y0+15, colorGrey40, colorGrey40);
    DrawData (" LastBuyQty: " + LastBuyQty, X0+155 , Y0, X0+305, Y0+15, colorGrey40, colorGrey40);
    DrawData (" LastSellPr: " + LastSellPrice, X0+310, Y0, X0+460, Y0+15, colorGrey40, colorGrey40);
    DrawData (" LastSellQty: " + LastSellQty, X0+465, Y0, X0+615, Y0+15, colorGrey40, colorGrey40);
    DrawData (" LastShortPr: " + LastShortPrice, X0+620, Y0, X0+770, Y0+15, colorGrey40, colorGrey40);
    DrawData (" LastShortQty: " + LastShortQty, X0+775 , Y0, X0+925, Y0+15, colorGrey40, colorGrey40);
    DrawData (" LastCoverPr: " + LastCoverPrice, X0+930, Y0, X0+1080, Y0+15, colorGrey40, colorGrey40);
    DrawData (" LastCoverQty: " + LastCoverQty, X0+1085, Y0, X0+1235, Y0+15, colorGrey40, colorGrey40);
   
    Y0 = 70;
   
    DrawData (" LTP : " + CurrentTradedPrice, X0, Y0, X0+125, Y0+15, LTPColor, LTPColor);
    DrawData (" LTQ : " + NumToStr(CurrentLTQ,1,0), X0+130, Y0, X0+255, Y0+15, LTQColor, LTQColor);
    DrawData (" Bid : " + CurrentBidPrice, X0+260, Y0, X0+385, Y0+15, AskColor, AskColor);
    DrawData (" Ask : " + CurrentAskPrice, X0+390, Y0, X0+515, Y0+15, BidColor, BidColor);
   
    NestOredrNo = ClientIdValue + NumToStr(Now(3),1,0) + "00" + StaticVarGet("OrderNo");
    DrawData (" NetQty : " + NetQty, X0+520, Y0, X0+670, Y0+15, NetQuantityColor, NetQuantityColor);
    DrawData (" NetValue : " + NetValue, X0+675, Y0, X0+900, Y0+15, NetValueColor, NetValueColor);
    DrawData (" Order No : " + NestOredrNo, X0+905, Y0, X0+1150, Y0+15, colorGrey40, colorGrey40);
   
}

_SECTION_END();



_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);

Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

_SECTION_BEGIN("MA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 10, 2, 200, 1 );
Plot( MA( P, Periods ), /*_DEFAULT_NAME()*/ "", ParamColor( "Color", colorGreen ), ParamStyle("Style", styleLine | styleNoLabel ) | styleNoRescale );
_SECTION_END();

_SECTION_BEGIN("EMA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 30, 2, 300, 1, 10 );
Plot( EMA( P, Periods ), /*_DEFAULT_NAME()*/ "", ParamColor( "Color", colorOrange ), ParamStyle("Style", styleLine | styleNoLabel) | styleNoRescale );
_SECTION_END();

_SECTION_BEGIN("Long MA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 45, 2, 400, 1 );
Plot( MA( P, Periods ), /*_DEFAULT_NAME()*/ "", ParamColor( "Color", colorYellow ), ParamStyle("Style", styleLine | styleNoLabel ) | styleNoRescale );
_SECTION_END();

_SECTION_BEGIN("BBands");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 100, 1 );
Width = Param("Width", 2, 0, 10, 0.05 );
Color = ParamColor("Color", colorLightGrey );
Color = ColorBlend( Color,  GetChartBkColor(), 0.5 );
Style = ParamStyle("Style", styleLine | styleNoLabel ) | styleNoRescale;;
Plot( bbt = BBandTop( P, Periods, Width ), /*"BBTop" + _PARAM_VALUES()*/ "", Color, Style );
Plot( bbb = BBandBot( P, Periods, Width ), /*"BBBot" + _PARAM_VALUES()*/ "", Color, Style );
PlotOHLC( bbt, bbt, bbb, bbb, "", ColorBlend( Color, GetChartBkColor(), 0.7 ), styleNoLabel | styleCloud | styleNoRescale, Null, Null, Null, -1 );
_SECTION_END();

_SECTION_BEGIN("Volume");
Color = ParamColor("Color", ColorRGB( 128, 128, 192 ) );
Plot( Volume, /*_DEFAULT_NAME()*/"", ColorBlend( Color, GetChartBkColor(), 0.2  ), styleNoTitle | ParamStyle( "Style", styleHistogram | styleOwnScale | styleThick | styleNoLabel, maskHistogram  ), 2 );
_SECTION_END();

High Low Bracket for Amibroker (AFL) with Audio Sound

High Low Bracket for Amibroker (AFL)








HX=Ref(H,-1);
LX=Ref(L,-1);
TicksOffset= Param("TicksOffset",0.0001,0.0001,0.50,0.0001);
y0=LastValue(HX)+TicksOffset;
y1=LastValue(LX)-TicksOffset;
Offset = 2;
for(i=BarCount-2;i>1;i--)
{
bars = i;
i = 0;
}
Plot(LineArray(bars-Offset, y0, BarCount, y0,1), "", colorDarkRed, styleLine|styleLine|styleNoLabel, Null, Null, Offset);
Plot(LineArray(bars-Offset, y1, BarCount, y1,1), "", colorDarkRed, styleLine|styleLine|styleNoLabel, Null, Null, Offset);
for (i=bars; i <BarCount;i++)
{
if (C[i]>y0)
color[i]=colorBlue;
else
color[i] = Null;
PlotText(""+Y0, BarCount+1,Y0,Null,color[i]);
AlertIf( C[i]>y0, "SOUND C:\\Windows\\Media\\ringout.wav", "Audio alert", 1 );
}
for (i=bars; i <BarCount;i++)
{
if (C[i]<y1)
color[i]=colorRed;
else
color[i] = Null;
PlotText(""+Y1, BarCount+1,Y1,Null,color[i]);
AlertIf( C[i]<y1, "SOUND C:\\Windows\\Media\\ringout.wav", "Audio alert", 1 );
}

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

All on One for Amibroker (AFL)


All on One for Amibroker (AFL)






_SECTION_BEGIN("SuperTrend");
SetBarsRequired(100000,0);
GraphXSpace = 15;
SetChartOptions(0,chartShowArrows|chartShowDates);

Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle |
ParamStyle("Style") | GetPriceStyle() );

PositionSize = 100000;

Factor=Optimize("Factor",2,2,10,1);
Pd=Optimize("ATR Periods",11,1,20,1);
Up=(H+L)/2+(Factor*ATR(Pd));
Dn=(H+L)/2-(Factor*ATR(Pd));
iATR=ATR(Pd);
TrendUp=TrendDown=Null;
trend[0]=1;
changeOfTrend=0;
flag=flagh=0;

for (i = 1; i <BarCount-1; i++) {
      TrendUp[i] = Null;
      TrendDown[i] = Null;
    
      trend[i]=1;
  
     
      if (Close[i]>Up[i-1]) {
         trend[i]=1;
         if (trend[i-1] == -1) changeOfTrend = 1;
        
      }
      else if (Close[i]<Dn[i-1]) {
         trend[i]=-1;
         if (trend[i-1] == 1) changeOfTrend = 1;
      }
      else if (trend[i-1]==1) {
         trend[i]=1;
         changeOfTrend = 0;      
      }
      else if (trend[i-1]==-1) {
         trend[i]=-1;
         changeOfTrend = 0;
      }

      if (trend[i]<0 && trend[i-1]>0) {
         flag=1;
      }
      else {
         flag=0;
      }
     
      if (trend[i]>0 && trend[i-1]<0) {
         flagh=1;
      }
      else {
         flagh=0;
      }
     
      if (trend[i]>0 && Dn[i]<Dn[i-1]){
         Dn[i]=Dn[i-1];
                }
     
      if (trend[i]<0 && Up[i]>Up[i-1])
        { Up[i]=Up[i-1];
                }
     
      if (flag==1)
       {  Up[i]=(H[i]+L[i])/2+(Factor*iATR[i]);;
        }
      if (flagh==1)
        { Dn[i]=(H[i]+L[i])/2-(Factor*iATR[i]);;
         }
      if (trend[i]==1) {
         TrendUp[i]=Dn[i];
         if (changeOfTrend == 1) {
            TrendUp[i-1] = TrendDown[i-1];
            changeOfTrend = 0;
         }
      }
      else if (trend[i]==-1) {
         TrendDown[i]=Up[i];
         if (changeOfTrend == 1) {
            TrendDown[i-1] = TrendUp[i-1];
            changeOfTrend = 0;
         }
      }
   }

Plot(TrendUp,"Trend",colorGreen);
Plot(TrendDown,"Down",colorRed);

Buy = trend==1;
Sell=trend==-1;

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

BuyPrice=ValueWhen(Buy,C);
SellPrice=ValueWhen(Sell,C);
ShortPrice=ValueWhen(Short,C);
CoverPrice=ValueWhen(Cover,C);

PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);      
             
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);   
                
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);

_SECTION_END();

_SECTION_BEGIN("MA");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( MA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();

_SECTION_BEGIN("Label");


GfxSetTextAlign( 6 );
FS=Param("Font Size",16);
GfxSelectFont("Arial", FS, 700, True );
GfxSetBkMode(0);
GfxSetTextColor( colorLightOrange );
Hor=Param("Horizonta Position",1000);
Ver=Param("Vertica Position",18);
GfxTextOut(""+C, Hor , Ver );
YC=TimeFrameGetPrice("C",inDaily,-1);
DD=Prec(C-YC,2);
xx=Prec((DD/YC)*100,2);
FS2=Param("Font Size2",11);
GfxSelectFont("Arial", FS2,11, 700, True );
GfxSetBkMode( colorGreen );
Hor1=Param("Horizontal Position",1000);
Ver1=Param("Vertical Position",1); 
GfxSetTextColor( colorLightOrange );
GfxTextOut(""+DD+"  ("+xx+"%)", Hor1 , Ver1+45 );

dec = (Param("Decimals",2,0,7,1)/10)+1;

Title =EncodeColor(255)+ Name() + " " + EncodeColor(30) + Date() +
" " + EncodeColor(5) + "{{INTERVAL}} " +
EncodeColor(255)+ " Open = "+ EncodeColor(30)+ WriteVal(O,dec) +
EncodeColor(255)+ " High = "+ EncodeColor(30)+ WriteVal(H,dec) +
EncodeColor(255)+ " Low = "+ EncodeColor(30)+ WriteVal(L,dec) +
EncodeColor(255)+ " Close = "+ EncodeColor(35)+ WriteVal(C,dec)+
EncodeColor(255)+ " Volume = "+ EncodeColor(30)+ WriteVal(V,1) ;

_SECTION_END();

_SECTION_BEGIN("Advance Trenlines with Candle Pivots");
farback = Param("How Far back to go", 100, 50, 5000, 10);
nBars = Param("Number of bars", 12, 5, 40);
aHPivs = H - H;
aLPivs = L - L;
aHPivHighs = H - H;
aLPivLows = L - L;
aHPivIdxs = H - H;
aLPivIdxs = L - L;
nHPivs = 0;
nLPivs = 0;
lastHPIdx = 0;
lastLPIdx = 0;
lastHPH = 0;
lastLPL = 0;
curPivBarIdx = 0;
aHHVBars = HHVBars(H, nBars);
aLLVBars = LLVBars(L, nBars);
aHHV = HHV(H, nBars);
aLLV = LLV(L, nBars);
aVisBars = Status("barvisible");
nLastVisBar = LastValue(Highest(IIf(aVisBars, BarIndex(), 0)));
_TRACE("Last visible bar: " + nLastVisBar);
curBar = (BarCount - 1);
curTrend = "";
if (aLLVBars[curBar] < aHHVBars[curBar])
{
curTrend = "D";
}

else
{
curTrend = "U";
}

for (i = 0; i < farback; i++)
{
curBar = (BarCount - 1) - i;
if (aLLVBars[curBar] < aHHVBars[curBar])
{
if (curTrend == "U")
{
curTrend = "D";
curPivBarIdx = curBar - aLLVBars[curBar];
aLPivs[curPivBarIdx] = 1;
aLPivLows[nLPivs] = L[curPivBarIdx];
aLPivIdxs[nLPivs] = curPivBarIdx;
nLPivs++;
}
}
else
{
if (curTrend == "D")
{
curTrend = "U";
curPivBarIdx = curBar - aHHVBars[curBar];
aHPivs[curPivBarIdx] = 1;
aHPivHighs[nHPivs] = H[curPivBarIdx];
aHPivIdxs[nHPivs] = curPivBarIdx;
nHPivs++;
}
}
}

curBar = (BarCount - 1);
candIdx = 0;
candPrc = 0;
lastLPIdx = aLPivIdxs[0];
lastLPL = aLPivLows[0];
lastHPIdx = aHPivIdxs[0];
lastHPH = aHPivHighs[0];
if (lastLPIdx > lastHPIdx)
{
candIdx = curBar - aHHVBars[curBar];
candPrc = aHHV[curBar];
if (lastHPH < candPrc AND candIdx > lastLPIdx AND candIdx < curBar)
{
aHPivs[candIdx] = 1;
for (j = 0; j < nHPivs; j++)
{
aHPivHighs[nHPivs - j] = aHPivHighs[nHPivs - (j + 1)];
aHPivIdxs[nHPivs - j] = aHPivIdxs[nHPivs - (j + 1)];
}
aHPivHighs[0] = candPrc;
aHPivIdxs[0] = candIdx;
nHPivs++;
}
}

else
{
candIdx = curBar - aLLVBars[curBar];
candPrc = aLLV[curBar];
if (lastLPL > candPrc AND candIdx > lastHPIdx AND candIdx < curBar)
{
aLPivs[candIdx] = 1;
for (j = 0; j < nLPivs; j++)
{
aLPivLows[nLPivs - j] = aLPivLows[nLPivs - (j + 1)];
aLPivIdxs[nLPivs - j] = aLPivIdxs[nLPivs - (j + 1)];
}
aLPivLows[0] = candPrc;
aLPivIdxs[0] = candIdx;
nLPivs++;
}
}

for (k = 0; k < nHPivs; k++)
{
_TRACE("High pivot no. " + k + " at barindex: " + aHPivIdxs[k] + ", " + WriteVal(ValueWhen(BarIndex() == aHPivIdxs[k], DateTime(), 1), formatDateTime) + ", " + aHPivHighs[k]);
}

a1 = ahpivs == 1;
a2 = alpivs == 1;
PlotShapes(a1 *shapeSmallCircle, colorLightOrange, 0, H, Offset = 5);
PlotShapes(a2 *shapeSmallCircle, colorLightOrange, 0, L, Offset = -5);


Para = ParamToggle("Plot Parallel Lines","Off,On");
ColorS= ParamColor("Support",colorLightOrange);
ColorR= ParamColor("Resistance",colorLightOrange);
x = Cum(1);
s1 = L;
s11 = H;
pS = a2 == 1;


endt = LastValue(ValueWhen(ps,x,1));
startt = LastValue(ValueWhen(ps,x,2));
ends = LastValue(ValueWhen(ps,S1,1));
starts = LastValue(ValueWhen(ps,S1,2));
dtS = endt - startt;
aS = (endS - startS) / dtS;
bS = endS;
trendlineS = aS *(x - endt) + bS;
g3 = IIf(x > startt - 10, trendlineS, Null);
Plot(g3, "", colors );
pR = a1 == 1;
endt1 = LastValue(ValueWhen(pr,x,1));
startt1 = LastValue(ValueWhen(pr,x,2));
endr = LastValue(ValueWhen(pr,S11,1));
startr = LastValue(ValueWhen(pr,S11,2));
dtR = endt1 - startt1;
aR = (endR - startR) / dtR;
bR = endR;
trendlineR = aR *(x - endt1) + bR;
g4 = IIf(x > startT1 - 10, trendlineR, Null);
Plot(g4, "", colorr );

acd = log(endr/startr)/(endt1-startt1);
res1 = exp((x-endt1)*acd)*endr;
RRL = ROC(res1,1);
bcd = log(ends/starts)/(endt-startt);
sup1= exp((x-endt)*bcd)*ends;
RSL = ROC(sup1,1);

Low_Value = LastValue(Ref(LLV(L,endt1-startt1),-(x-endt1)));
x2 = LastValue(ValueWhen(L==Low_Value & x>startt1 & x<endt1,x));
PLL = IIf(LastValue(x)-x2>5,exp((x-x2)*acd)*Low_Value,Null);
Hi_Value = LastValue(Ref(HHV(H,endt-startt),-(x-endt)));
x3 = LastValue(ValueWhen(H==Hi_Value & x>startt & x<endt,x));
PHL = IIf(LastValue(x)-x3>5,exp((x-x3)*bcd)*Hi_Value,Null);
SLabs = sup1-Ref(sup1,-1); RLabs = res1-Ref(res1,-1);
ROC2SL = (SLabs/C)*100; ROC2RL = (RLabs/C)*100;
PLLd = abs((LastValue(C)/LastValue(PLL))-1)<0.01*100;
PHLd = abs((LastValue(C)/LastValue(PHL))-1)<0.01*100;
barvisible = Status("barvisible");
firstvisiblebar = barvisible & NOT
Ref(barvisible,-1);
HHvisible = LastValue(HighestSince(firstvisiblebar,High));
LLvisible = LastValue(LowestSince(firstvisiblebar,Low));
RaH = HHvisible *1.05; RaL = LLVisible *0.95;
AnZ= starts==0 OR ends==0 OR startr==0 OR endr==0;
PLplot = IIf(x-x2>=0 & abs(LastValue(L/PLL)-1) <abs(LastValue((100/1000)*ATR(14))) & PLL>RaL & PLL<RaH & NOT AnZ,PLL,IIf(x-x2>=0 & RaL==0 & PLLd & abs(LastValue(L/PLL)-1) <abs(LastValue((100/1000)*ATR(14)))& NOT AnZ,PLL,Null));
PHplot = IIf(x-x3>=0 & abs(LastValue(H/PHL)-1) <abs(LastValue((100/1000)*ATR(14))) & PHL>RaL & PHL<RaH & NOT AnZ,PHL,IIf(x-x3>=0 & RaL==0 & PHLd & abs(LastValue(H/PHL)-1) <abs(LastValue((100/1000)*ATR(14)))& NOT AnZ,PHL,Null));
Plot(IIf(Para,PLplot,Null)," ",colorr,styleDashed,maskDefault+styleNoRescale);
Plot(IIf(Para,PHplot,Null)," ",colors,styleDashed,maskDefault+styleNoRescale);
_SECTION_END();


_SECTION_BEGIN("Fibonacci");



Period = Param("Period", 5, 1, 50);
ShowExt = ParamToggle("Show Extension ?", "No|Yes");


Period = Period*(13*.618);

Hhb = LastValue(Ref(HHVBars(H, Period), -1))+1;
Llb = LastValue(Ref(LLVBars(L, Period), -1))+1;
Hv = LastValue(Ref(HHV(H, Period), -1));
Lv = LastValue(Ref(LLV(L, Period), -1));

Range = (Hv - Lv);
LText = "  0 %, 23.6 %, 38.2 %, 50  %, 61.8 %, 78.6 %, 100 %,127 % ,161.8 %,  200 %";
if(Hhb > Llb)
{
Levels[0] = Lv;
Levels[1]= (Range *.236)+Levels[0];
Levels[2]= (Range *.382)+Levels[0];
Levels[3]= (Range *.5)+Levels[0];
Levels[4]= (Range *.618)+Levels[0];
Levels[5]= (Range *.786)+Levels[0];
Levels[6]= Hv;
Levels[7]= (Range *.270)+Levels[6];
Levels[8]= (Range *.618)+Levels[6];
Levels[9]= (Range )+Levels[6];
x0 = BarCount - 1 - Llb;
x1 = BarCount - 1 - Hhb;
}
else
{
Levels[0]= Hv;
Levels[1]= Levels[0]- (Range *.236);
Levels[2]= Levels[0]- (Range *.382);
Levels[3]= Levels[0]- (Range *.5);
Levels[4]= Levels[0]- (Range *.618);
Levels[5]= Levels[0]- (Range *.786);
Levels[6]= Lv;
Levels[7]= Levels[6]- (Range *.270);
Levels[8]= Levels[6]- (Range *.618);
Levels[9]= Levels[6]- (Range );
x0 = BarCount - 1 - Hhb;
x1 = BarCount - 1 - Llb;
}



for(i=0; i<10; i++)
{
if(i!=6)
x = x0;
else
x = x1;
if(i<7 OR ShowExt)
{
Plot(LineArray(x, Levels[i], BarCount, Levels[i]), "", i+2, styleDashed);
PlotText(StrExtract(LText, i), BarCount, Levels[i], i+2);
}
}




_SECTION_END();

15 or 30 Min Indian Currency Market for Amibroker (AFL)


15 or 30 Min Indian Currency Market for Amibroker (AFL)




_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
Plot( C, "Close", colorDefault, styleNoTitle | GetPriceStyle() );

_SECTION_END();

_SECTION_BEGIN(" Settings");
Periods = Param("Call Sensitivity", 3, 2, 40, 1 );
accm = Param("StopLoss Sensitivity", 0.16, 0, 1, 0.001 );
_SECTION_END();

_SECTION_BEGIN("Buy Sell Declaration");
VAL=MA( Close, Periods);
B  = C>Val;
S = C<Val;
B1 = Ref(B,-1);
S1 = Ref(S,-1);

Sell = S AND S1;
Buy  = B AND B1;

Buy=ExRem(Buy,Sell) ;
Sell=ExRem(Sell,Buy);
PlotShapes( IIf( Buy, shapeUpArrow, shapeNone ), colorBrightGreen ,layer = 0, yposition = C, offset = -45 );
PlotShapes( IIf( Sell, shapeDownArrow, shapeNone ), colorRed ,layer = 0, yposition = C, offset = -45 );
_SECTION_END();

_SECTION_BEGIN("MsgBoards");
Call=IIf(Sell,Sell,IIf(Buy,Buy,0));
BuyPrice=ValueWhen(Buy,H);
SellPrice=ValueWhen(Sell,L);
CP=IIf(Sell,SellPrice,IIf(Buy,BuyPrice,0));
Callprice=ValueWhen(Buy OR Sell,CP);
YC=TimeFrameGetPrice("C",inDaily,-1);
TO=TimeFrameGetPrice("O",inDaily,0);
YH=TimeFrameGetPrice("H",inDaily,-1);
YL=TimeFrameGetPrice("L",inDaily,-1);
MKTRANGE=YH-YL;


acc = 0.15;
VALSAR=SAR(acc,accm);



for(i=BarCount-1;i>1;i--)
{
if(Buy[i]  == 1)
{
sig = "BUY";
entry = BuyPrice[i];
GfxSelectSolidBrush( colorDarkGreen );
GfxSelectPen( colorLime, 1);
GfxTextOut(" 15 / 30 Minutes Currency India", 13 , 360);
GfxTextOut("Version 1.0 Final - 11th April 2015", 13, 390);


stoploss=IIf(Call==Buy AND VALSAR<C,VALSAR,IIf(Call==Sell AND VALSAR>C,VALSAR,0.0));
slcolor=IIf(VALSAR<C,colorRed,colorGrey50);
Plot( VALSAR, "stop line", slcolor , styleStaircase | styleDashed | styleNoTitle);

i = 0;
}
if(Sell[i] == 1)
{
sig = "SELL";
entry = SellPrice[i] ;


stoploss=IIf(Call==Buy AND VALSAR<C,VALSAR,IIf(Call==Sell AND VALSAR>C,VALSAR,0.0));
slcolor=IIf(VALSAR>C,colorLime,colorGrey50);
Plot( VALSAR, "stop line", slcolor , styleStaircase| styleDashed | styleNoTitle);

bars = i;
i = 0;
}
}

GfxRoundRect( 5, 350, 150, 290 , 7, 7 );

GfxSelectFont("Times New Roman", 20, 700, True );
GfxSetBkMode( colorPink ); 
GfxSetTextColor (colorYellow );
GfxTextOut("  15 - 30 Minutes Currency India", 55 , 520);
GfxSelectFont("Times New Roman", 13, 700, True );
GfxSetTextColor (colorYellow);
GfxTextOut(" 15 or 30 Minutes on USD/INR - GBP/INR - JPY/INR - EUR/INR", 55 , 550);


GfxSetTextColor (colorWhite);
GfxSelectFont("Times New Roman", 11, 700, True );
GfxTextOut("Yesterdays Closing : "+ Prec(YC,2), 5 , 55);
GfxTextOut("Todays Open : "+ Prec(TO,2), 5 , 70);
GfxTextOut("YESTERDAY HIGH/LOW :  "+ Prec(YH,2)+ "  /  "+ Prec(YL,2), 5 , 85);
GfxTextOut("YESTERDAYS MARKET RANGE :  "+ Prec(MKTRANGE,2), 5 , 100);

GfxSetTextColor (colorWhite );
GfxSelectFont("Times New Roman", 11, 700, True );
GfxSetBkMode( colorBlack );

GfxSelectFont("Times New Roman", 11, 700, True );
GfxSetBkMode( colorBlack );
GfxTextOut(" " + sig + " @ "+ Callprice, 13 , 300);
GfxTextOut("Stop Loss : " + stoploss, 13 , 330);

NoteSet("", "
Stratergy Name :
K.I.S.S - 15 / 30 Minutes Currency India Version 1.0 Final.

Key Features:
1) intraday book 10 PIPS PROFIT OR Hold till call change
2) Excellent Capability to Catch Trends way before they start
3) Little Sensative, Hence False Calls MAy arrive, but Stop Loss is Very Tight AND Small.
4) Contains all - Call, Exits OR
5) Usual Stop Loss is Less than 7 pips, you Can exit early if you see previous Candle High/Low break. The Stratergy was designed for Safety

This is a Very Simple yet powerful Trading Stratergy
Developed for Cash/Currency Indian Market

The stratergy is to be used On intraday OR Carryforward. Depends On 15 Minutes OR 30 Minutes Charts.

Trading Tips:
Money MAnagement: Use Only 2 - 10% Of your trading Capital.
Try to Book 80% Of your profits within the FIRst 10 pips for good MoneyManagement.

In case Of any issues/Help needed you MAy Consult me On +91 9167446412 OR nileshnks@yahoo.com

Full Credits AND
Analysis / Programmed by : Nilesh K Shirke
India : Ghatkopar East - Mumbai
Thanks for Family Support AND Amibroker Software

Nothing is proven official without Mathemathic Testing:
Tested On NSECDS/MCX USDINR, JPYINR, GBPINR, EURINR with Paper Trading with the Following Stats
Win Streak is calculated considering 2 paisa brokerage.
AnyTrade Greater than 0.02 paisa is considered a Win.
Sometimes Stoploss also gives in Profit, that is included in Win count.

Maths Stastic Result
Max Continous Win Streak : 3
Max Continous Loosing Streak : 13
Max Loss Pips Counts : 12 pips (currency 0.12 paisa)
15 Minutes on USDINR / GBPINR / JPYINR Back Testing 4 Trades Per Day till Profit.
Average Loss Pips Counts : 7 pips (currency 0.07 paisa)
Average GrossProfit Pips in 3 months Back data Test : 68 Pips Per Day (Currency 0.60 Paisa)
Average GrossLoss Pips in 3 months Back data Test : 26 Pips Per Day (Currency 0.26 Paisa)
Average Net Position in 3 Months Back Data Test: Profit . 42 Pips per Day (Currency 0.42 Pips per Day)

On an Average Monthly trade can give a return of more than 10% returns with this stratergy, with proper money management.
Kindly invest only 2% of the capital. do NOT invest more than 10% of your Account even in Highest confident situation.

Example:
for an Account of 2 Lakh, have a Stoploss of 2000 - 5000 Rupees per trade. So accordingly trade with limited lot sizes which enable you to have 2000 - 8000 profit per trade/Day trade.

Good Luck !!

");

_SECTION_END();