Announcement

Collapse
No announcement yet.

NinjaTrader help!!

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

  • NinjaTrader help!!

    I am trying to automate a very simple strategy with NinjaTrader. It is a dual moving average(always long or short) system. Unfortunately, I keep getting an error message ("Your scale out order can be a maximum size of 0"). I pulled the code off the Ninjatrader website. Does anyone either have a template code that I can alter, or any suggestions to my code? Thanks in advance, mel.

    var f = new File("ES 12-04SIM-101update.txt");
    var vEMA2 = new MAStudy(2, 0, "Close", MAStudy.SIMPLE);
    var vEMA5 = new MAStudy(5, 0, "Close", MAStudy.SIMPLE);
    var returnvalue = 0;

    function preMain(){
    setPriceStudy(true);
    setStudyTitle("dualma cross");
    }
    if(f.exists()) {
    f.open("rt");
    var stateline;
    stateline = f.readln();
    f.close();
    if (stateline != null){
    var PosCount = stateline.split(",");
    var s = PosCount[0]
    var position = s.substr(1,4);

    if (position == "FLAT") {
    returnvalue = 0;
    }
    if (position == "0") {
    returnvalue = 2;
    }
    if (position == "LONG") {
    returnvalue = 1;
    }
    if (position == "SHORT") {
    returnvalue = -1;
    }
    }
    }
    else {
    returnvalue = 0;
    }
    function main() {

    if (vEMA5.getValue(MAStudy.MA) > vEMA2.getValue(MAStudy.MA)) {
    if(returnvalue == 0) {
    var order = new File("order.txt");
    order.open("wt+");
    if(!order.isOpen()) {
    debugPrintln("Could not open file!");
    }
    else {
    order.writeln("ES 12-04,1,DAY,SELL,MKT,,,,,,,,SIM-101,");
    }
    order.close();
    }
    if(returnvalue == 2) {
    var order = new File("cancel.txt");
    order.cancel("wt+");
    if(!cancel.isOpen()) {
    debugPrintln("Could not open file!");
    }
    else {
    cancel.writeln("ES 12-04,SIM-101,");
    }
    order.close();
    var order = new File("order.txt");
    order.open("wt+");
    if(!order.isOpen()) {
    debugPrintln("Could not open file!");
    }
    else {
    order.writeln("ES 12-04,1,DAY,SELL,MKT,,,,,,,,SIM-101,");
    }
    order.close();
    }
    if(returnvalue == 1) {
    var reverse = new File("reverse.txt");
    reverse.open("wt+");
    if(!reverse.isOpen()) {
    debugPrintln("Could not open file!");
    } else {
    reverse.writeln("ES 12-04,1,,SIM-101,");
    }
    reverse.close();
    }
    }


    if (vEMA2.getValue(MAStudy.MA) > vEMA5.getValue(MAStudy.MA)) {
    if(returnvalue == 0) {
    var order = new File("order.txt");
    order.open("wt+");
    if(!order.isOpen()) {
    debugPrintln("Could not open file!");
    }
    else {
    order.writeln("ES 12-04,1,DAY,BUY,MKT,,,,,,,,SIM-101,");
    }
    order.close();
    }
    if(returnvalue == 2) {
    var order = new File("cancel.txt");
    order.cancel("wt+");
    if(!cancel.isOpen()) {
    debugPrintln("Could not open file!");
    }
    else {
    cancel.writeln("ES 12-04,SIM-101,");
    }
    order.close();
    var order = new File("order.txt");
    order.open("wt+");
    if(!order.isOpen()) {
    debugPrintln("Could not open file!");
    }
    else {
    order.writeln("ES 12-04,1,DAY,BUY,MKT,,,,,,,,SIM-101,");
    }
    order.close();
    }
    if(returnvalue == -1) {
    var reverse = new File("reverse.txt");
    reverse.open("wt+");
    if(!reverse.isOpen()) {
    debugPrintln("Could not open file!");
    } else {
    reverse.writeln("ES 12-04,,AUTO ES,SIM-101,");
    }
    reverse.close();
    }
    }

    }
    Last edited by melfarmer; 11-04-2004, 02:48 PM.
Working...
X