Announcement

Collapse
No announcement yet.

Help with Return Statement

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

  • Help with Return Statement

    Help- I have constructed a script, but I am stuck with debugging the Return statement.
    All I get from the script checker is:-
    "Syntax Error : Invalid return"
    I can see nothing invalid about it.
    Anyone got any ideas?

    Script below - hELP!!!
    //
    // This formula was created 14/7/03
    //



    var vMOM10 = new MOMStudy(10, "Close");
    var vEMA10_of_vMOM10 = new MAStudy(10, 0, vMOM10, MOMStudy.MOM, MAStudy.EXPONENTIAL);
    var vLastAlert = -1;
    var SimpleMA2= new MAStudy(2, 0 ,"Close", MAStudy.SIMPLE);
    var SimpleMA5 = new MAStudy(5, 0 ,"Close", MAStudy.SIMPLE);

    var RisingStopValue = 0;
    var FallingStopValue = 99999;


    var LongSoundDone = 0
    var ShortSoundDone = 0

    var nNewTrade; // New Trade Trigger 0 = OFF / 1 = ON
    var nsignal; // returns the direction of the trading signal
    var nTradeEntryPrice;
    var ProfitTarget1 = 5.0; //Not used by UltraMarkets
    var nStopLevel; //Global to hold the current stop loss level

    //0.05 = 5 ticks (probably) - Change the number below to adjust the stop loss.
    var nStopLossTolerance = 0.05


    //
    // SUBROUTINES BELOW HERE
    //

    function onAction1() {
    setPriceBarColor(Color.RGB(155,0,0));
    if (vLastAlert != 1) Alert.playSound("D:\\Program Files\\eSignal\\Sounds\\Warning.wav");
    vLastAlert = 1;
    }

    function onAction2() {
    setPriceBarColor(Color.RGB(0,128,0));
    if (vLastAlert != 2) Alert.playSound("D:\\Program Files\\eSignal\\Sounds\\Bullet.wav");
    vLastAlert = 2;
    }



    function ActionGoLong() {
    Strategy.doLong("Going Long", Strategy.MARKET, Strategy.NEXTBAR);
    if(LongSoundDone==0) {
    setPriceBarColor(Color.RGB(0,128,0));
    Alert.playSound("D:\\Program Files\\eSignal\\Sounds\\Applause.wav");
    LongSoundDone=1;
    ShortSoundDone=0;
    }
    }


    function ActionGoShort() {
    Strategy.doShort("Going Short", Strategy.MARKET, Strategy.NEXTBAR);
    if (ShortSoundDone==0) {
    setPriceBarColor(Color.RGB(155,0,0));
    Alert.playSound("D:\\Program Files\\eSignal\\Sounds\\ding.wav");
    LongSoundDone=0;
    ShortSoundDone=1;
    }
    }




    //
    // PRE-MAIN
    //

    function preMain() {
    /**
    * This function is called only once, before any of the bars are loaded.
    * Place any study or EFS configuration commands here.
    */
    setPriceStudy(true);
    setStudyTitle("Ultra Markets BackTester");
    setCursorLabelName("Line1", 0);
    setCursorLabelName("Lin2", 1);
    setDefaultBarStyle(PS_SOLID, 0);
    setDefaultBarStyle(PS_SOLID, 1);
    setDefaultBarFgColor(Color.RGB(196,60,60), 0);
    setDefaultBarFgColor(Color.RGB(60,60,196), 1);
    setDefaultBarThickness(1, 0);
    setDefaultBarThickness(1, 1);
    setPlotType(PLOTTYPE_LINE, 0);
    setPlotType(PLOTTYPE_LINE, 1);
    //setStudyMin(-10);
    //setStudyMax(10);
    //addBand(20, PS_SOLID, 1, Color.RGB(0,0,0));
    //addBand(80, PS_SOLID, 1, Color.RGB(0,0,0));

    // Un-comment the line below to do only close of bar calculations
    setComputeOnClose(true)
    nNewTrade=0;
    }


    //
    // MAIN
    //

    function main() {
    /**
    * The main() function is called once per bar on all previous bars, once per
    * each incoming completed bar, and if you don't have 'setComputeOnClose(true)'
    * in your preMain(), it is also called on every tick.
    */
    var v = SimpleMA2.getValue(MAStudy.MA);
    var v2 = SimpleMA5.getValue(MAStudy.MA);
    var NewStop;

    //DebugPrintln(“Sample text : “+close()+” : “+variable);
    //DebugPrintln(variable1+” : “+variable2+” : “+variable3);
    /*----------------------------------------------------------------
    // If new trade, get entry price – used for our profit target
    ----------------------------------------------------------
    This portion of the code identifies if a new trade has been issued and records the entry price of our trade.
    If no new trade has been triggered (nNewTrade == 1), then this portion of the code is ignored.
    ----------------------------------------------------------*/
    if ((Strategy.isInTrade() == true) && (nNewTrade == 1)) {
    // This sets the expected entry price of the current short trade
    nTradeEntryPrice = open();
    // This switches off the nNewTrade variable
    nNewTrade = 0; // Turn off NEW TRADE switch
    }

    /*----------------------------------------------------------------
    // Test for Profit Target Breach (ProfitTarget1)
    ----------------------------------------------------------
    This portion of the code identifies if our profit target has been reached and exits our trades.
    ----------------------------------------------------------*/
    /* if (Strategy.isInTrade() == true) && (Strategy.isShort() == true)) {
    // Check if the profit target has been reached/breached
    if (low() <= (nTradeEntryPrice - ProfitTarget1)) {
    // Profit Target Breached… Execute Cover order.
    Strategy.doCover("Short PT1 Exit", Strategy.STOP, Strategy.THISBAR, Strategy.getDefaultLotSize(), (nTradeEntryPrice – ProfitTarget1));
    }
    }
    if (Strategy.isInTrade() == true) && (Strategy.isLong() == true)) {
    // Check if the profit target has been reached/breached
    if (high() >= (nTradeEntryPrice + ProfitTarget1)) {
    // Profit Target Breached… Execute Sell order.
    Strategy.doSell("Long PT1 Exit", Strategy.STOP, Strategy.THISBAR, Strategy.getDefaultLotSize(), (nTradeEntryPrice + ProfitTarget1));
    }
    }
    */
    /*----------------------------------------------------------
    This portion of the code tests for a stop level breach and executes trades accordingly.
    ----------------------------------------------------------*/
    if ((Strategy.isInTrade() == true) && (Strategy.isShort() == true)) {
    // Check if the profit target has been reached/breached
    if (high() >= nStopLevel) {
    // Stop Breached… Execute Cover order.
    Strategy.doCover("Short Stop Exit", Strategy.STOP, Strategy.THISBAR, Strategy.getDefaultLotSize(), nStopLevel);
    }
    }

    if ((Strategy.isInTrade() == true) && (Strategy.isLong() == true)) {
    // Check if the profit target has been reached/breached
    if (low() <= nStopLevel) {
    // Stop Breached… Execute Sell order.
    Strategy.doSell("Long Stop Exit", Strategy.STOP, Strategy.THISBAR, Strategy.getDefaultLotSize(),nStopLevel);
    }
    }

    /*----------------------------------------------------------
    This portion of the code calculates and sets the new stop levels.
    ----------------------------------------------------------*/
    if ((Strategy.isInTrade() == true) && (Strategy.isShort() == true)) {
    NewStop = high(-1) + nStopLossTolerance ;
    if (NewStop < nStopLevel)
    nStopLevel = NewStop;
    }
    if ((Strategy.isInTrade() == true) && (Strategy.isLong() == true)) {
    NewStop = low() - nStopLossTolerance ;
    if (NewStop > nStopLevel)
    nStopLevel = NewStop;
    }
    /*----------------------------------------------------------------
    // Identify new trade signals…
    ----------------------------------------------------------------- */
    if (Strategy.isInTrade() == false) {
    if (v > V2) {
    nNewTrade = 1; // New Trade Trigger
    nsignal = 1; // Buy Signal – Trade Type
    }
    if (v < v2) {
    nNewTrade = 1; // New Trade Trigger
    nsignal = -1; // Sell Signal – Trade Type
    }
    }
    /*----------------------------------------------------------------
    // Execute Trades ONLY if nNewTrade is triggered ....
    ----------------------------------------------------------------- */
    if (nNewTrade == 1) { //Execute New Trade
    // new or reversed trade position
    if (Strategy.isInTrade() == true) {
    /* DO NOTHING IF ALREADY GOT POSITION
    if ((nsignal > 0) && (Strategy.isShort() == true)) {
    Strategy.doCover("Exit Short", Strategy.MARKET, Strategy.NEXTBAR);
    Strategy.doLong("Rev Long", Strategy.MARKET, Strategy.NEXTBAR);
    nStopLevel = low(-1) - 0.25;
    }
    if ((nsignal < 0) && (Strategy.isLong() == true)) {
    Strategy.doSell("Exit Long", Strategy.MARKET, Strategy.NEXTBAR);
    Strategy.doShort("Rev Short", Strategy.MARKET, Strategy.NEXTBAR);
    nStopLevel = high(-1) + 0.25;
    END OF DO NOTHING */
    }
    } else {
    if ((nsignal > 0)) {
    Strategy.doLong("Go Long", Strategy.MARKET, Strategy.NEXTBAR);
    nStopLevel = low(-1) - 0.25;
    }
    if ((nsignal < 0)) {
    Strategy.doShort("Go Short", Strategy.MARKET, Strategy.NEXTBAR);
    nStopLevel = high(-1) + 0.25;
    }
    } // end if IN TRADE
    } // END EXECUTE NEW TRADE

    return (v);
    }
    //Return NEW Array(v, v2);
    //Strategy.getPositionPrice()
    //);




    function postMain() {
    /**
    * The postMain() function is called only once, when the EFS is no longer used for
    * the current symbol (ie, symbol change, chart closing, or application shutdown).
    */
    }

  • #2
    Hello mgladwin,

    This message typically means that you have an extra brace or are missing one somewhere. Looks like the end brace in this section is an extra one.

    PHP Code:
    /*----------------------------------------------------------
    This portion of the code tests for a stop level breach and executes trades accordingly.
    ----------------------------------------------------------*/
        
    if ((Strategy.isInTrade() == true) && (Strategy.isShort() == true)) {
            
    // Check if the profit target has been reached/breached
            
    if (high() >= nStopLevel) {
            
    // Stop Breached… Execute Cover order.
            
    Strategy.doCover("Short Stop Exit"Strategy.STOPStrategy.THISBARStrategy.getDefaultLotSize(), nStopLevel);
        }
    //}   <-- This brace looks like the culpret. 
    Jason K.
    Project Manager
    eSignal - an Interactive Data company

    EFS KnowledgeBase
    JavaScript for EFS Video Series
    EFS Beginner Tutorial Series
    EFS Glossary
    Custom EFS Development Policy

    New User Orientation

    Comment

    Working...
    X