Announcement

Collapse
No announcement yet.

Help with multiple signals excecuting.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help with multiple signals excecuting.

    Hi all

    I am trying to wirte an efs that is automated and sends signals to my sim trading pad (NinjaTrader). I got this to work with esignals backtesting but am having trouble getting it to work with live data.

    It is excecuting trades on every candle rather then just the first one. Any ideas of what might need changing would be greatly appreciated. I have run out of ideas!!

    Thanks

    Min

    See efs below

    var vSMA5 = new MAStudy(5, 0, "Close", MAStudy.SIMPLE);
    var vSMA15 = new MAStudy(15, 0, "Close", MAStudy.SIMPLE);
    var vUpTrend = null;
    var vDownTrend = null;
    var vValue = -1;
    var Target = null;
    var Stop = null;
    x = null;
    y = null;
    var dll = new DLL("NtDirect.dll");
    var orderPlaced = false;
    isFlat = false
    isInLong = false
    IsInShort = false

    function preMain()
    {
    setPriceStudy(true);
    setStudyTitle("Auto Trial");
    setCursorLabelName("5MA", 0);
    setCursorLabelName("15MA", 1);
    setDefaultBarFgColor(Color.maroon, 0);
    setDefaultBarFgColor(Color.teal, 1);
    setPlotType(PLOTTYPE_LINE, 0);
    setPlotType(PLOTTYPE_LINE, 1);
    setDefaultBarStyle(PS_SOLID, 0);
    setDefaultBarStyle(PS_SOLID, 1);
    setDefaultBarThickness(2, 0);
    setDefaultBarThickness(2, 1);
    setComputeOnClose(true)
    dll.addFunction("Connected", DLL.INT, DLL.STDCALL, "Connected", DLL.INT);
    dll.addFunction("Command", DLL.INT, DLL.STDCALL, "Command", DLL.STRING, DLL.STRING, DLL.STRING, DLL.STRING, DLL.INT, DLL.STRING, DLL.DOUBLE,
    DLL.DOUBLE, DLL.STRING, DLL.STRING, DLL.STRING, DLL.STRING, DLL.STRING);
    dll.addFunction("MarketPosition", DLL.INT, DLL.STDCALL, "MarketPosition", DLL.STRING, DLL.STRING);
    }

    debugClear()
    function main() {

    myVar = sma( 5 );
    x = myVar + 2.5;
    y = myVar -2.5;
    trade = NTMarketPosition("")
    if (trade == 0) {isFlat = true}
    if (trade > 0) {isInLong = true}
    if (trade < 0) {isInShort = true}

    if (vSMA5.getValue(MAStudy.MA) < vSMA15.getValue(MAStudy.MA) &&
    (vValue != 1)) {
    onAction3()
    }
    if (vSMA5.getValue(MAStudy.MA) > vSMA15.getValue(MAStudy.MA) &&
    (vValue != 2)) {
    onAction4()
    }
    if (getBarState()==BARSTATE_NEWBAR) {
    if (isLastBarOnChart() && NTConnected(1))
    {
    if (vSMA5.getValue(MAStudy.MA) > vSMA15.getValue(MAStudy.MA) &&
    vSMA5.getValue(MAStudy.MA, -1) < vUpTrend &&
    vSMA5.getValue(MAStudy.MA) > vUpTrend);
    {if (isFlat)
    {(NTBuyMarket("", 1))
    debugPrintln("Position size1: " + NTMarketPosition(""));}
    else (isInShort);
    {(NTBuyMarket("", 2) )
    debugPrintln("Position size2: " + NTMarketPosition(""));
    drawShapeRelative(0, low(-2), Shape.UPARROW, "", Color.purple, Shape.TOP);}
    // debugPrintln("Sell entry = " +
    } } }
    if (getBarState()==BARSTATE_NEWBAR){
    if (isLastBarOnChart() && NTConnected(1))
    {
    if (vSMA5.getValue(MAStudy.MA) < vSMA15.getValue(MAStudy.MA) &&
    vSMA5.getValue(MAStudy.MA, -1) > vDownTrend &&
    vSMA5.getValue(MAStudy.MA) < vDownTrend);
    {if (isFlat)
    {(NTSellMarket("", 1))
    debugPrintln("Position size3: " + NTMarketPosition(""));}
    else (isInLong)
    {(NTSellMarket("", 2) )
    debugPrintln("Position size4: " + NTMarketPosition(""));
    Strategy.doLong("Long", Strategy.CLOSE, Strategy.THISBAR)
    drawShapeRelative(0, high(-2), Shape.DOWNARROW, "", Color.blue, Shape.BOTTOM);}
    // debugPrintln("Buy entry = " + getValue(barType, close))
    } } }
    return new Array(
    vSMA5.getValue(MAStudy.MA),
    vSMA15.getValue(MAStudy.MA)
    );
    }
    //{{Action_3
    function onAction3() {
    // drawShapeRelative(0, high(-2), Shape.DOWNARROW, "", Color.RGB(255,0,0), Shape.BOTTOM);
    // debugPrintln("y= " + y);
    drawLineRelative(0, (y), +25, (y), PS_SOLID, 2, Color.red, getValue("RawTime") + "xdownpt");
    vDownTrend = y;
    // debugPrintln("DownTrend = " + vDownTrend);
    vValue = 1;
    }
    //{{Action_4
    function onAction4() {
    // drawShapeRelative(0, low(-2), Shape.UPARROW, "", Color.RGB(0,255,0), Shape.TOP);
    // debugPrintln("x= " + x);
    drawLineRelative(0, (x), +25, (x), PS_SOLID, 2, Color.green, getValue("RawTime") + "xuppt");
    vUpTrend = x;
    // debugPrintln("UpTrend = " + vUpTrend);
    vValue = 2;
    }
    function NTCommand(command, account, action, quantity, orderType, limitPrice, stopPrice, timeInForce, oco, orderId, template, strategy) {
    return dll.call("Command", command, "", "ES 12-08", action, quantity, orderType,
    limitPrice, stopPrice, timeInForce, oco, orderId, template, strategy);
    }
    function NTConnected(showMessage) {
    return (dll.call("Connected", showMessage) == 0)
    }
    function NTBuyMarket(orderId, quantity) {
    return NTCommand("Place", "", "Buy", 1, "Market", 0, 0, "", "", "", "", "");
    }
    function NTSellMarket(orderId, quantity) {
    return NTCommand("Place", "", "Sell", quantity, "Market", 0, 0, "", "", orderId, "", "");
    }
    function NTMarketPosition(account) {
    return dll.call("MarketPosition", "ES 12-08", "");
    }

  • #2
    Nevermind, I think I have it worked out

    Comment

    Working...
    X