Announcement

Collapse
No announcement yet.

How do I take profits?

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

  • How do I take profits?

    Hi there,

    I was hoping someone could tell me how to backtest taking profits based on an amount rather than an indicator.

    I've looked at backtesting 12 efs tut 1234, all the java videos, etc.

    I just want to test different price targets and stops on different moving average crosses.

    Can I use the formula wizard for this, or do I have to write it clean.


    any help would be appreciated.

    Heres my lame code so far:

    //{{EFSWizard_Description
    //
    // This formula was generated by the Alert Wizard
    //
    //}}EFSWizard_Description


    //{{EFSWizard_Declarations
    var vSMA10 = new MAStudy(10, 0, "Close", MAStudy.SIMPLE);
    var vSMA20 = new MAStudy(20, 0, "Close", MAStudy.SIMPLE);
    var vLastAlert = -1;
    //}}EFSWizard_Declarations


    function preMain() {
    /**
    * This function is called only once, before any of the bars are loaded.
    * Place any study or EFS configuration commands here.
    */
    //{{EFSWizard_PreMain
    setPriceStudy(true);
    setStudyTitle("ma profit take");
    //}}EFSWizard_PreMain

    }

    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.
    */

    //{{EFSWizard_Expressions
    //{{EFSWizard_Expression_1
    if (
    Strategy.isInTrade() == false &&
    Strategy.isLong() == false &&
    Strategy.isShort() == false &&
    vSMA10.getValue(MAStudy.MA) > vSMA20.getValue(MAStudy.MA)
    ) onAction1()
    //}}EFSWizard_Expression_1

    //{{EFSWizard_Expression_2
    else if (
    Strategy.isInTrade() == true &&
    vSMA10.getValue(MAStudy.MA) > vSMA20.getValue(MAStudy.MA) &&
    Strategy.isLong() == true
    ) onAction2();
    //}}EFSWizard_Expression_2

    //}}EFSWizard_Expressions


    //{{EFSWizard_Return
    return null;
    //}}EFSWizard_Return

    }

    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).
    */
    }

    //{{EFSWizard_Actions
    //{{EFSWizard_Action_1
    function onAction1() {
    Alert.addToList(getSymbol(), "", Color.RGB(0,0,0), Color.RGB(195,0,0));
    drawShapeRelative(0, low(), Shape.CIRCLE, "", Color.RGB(155,0,0), Shape.TOP);
    Strategy.doLong("ma croos up", Strategy.CLOSE, Strategy.THISBAR, Strategy.DEFAULT, 0);
    if (vLastAlert != 1) Strategy.setStop(0.05);
    vLastAlert = 1;
    }
    //}}EFSWizard_Action_1

    //{{EFSWizard_Action_2
    function onAction2() {
    if (vLastAlert != 2) Strategy.doSell("", Strategy.LIMIT, Strategy.NEXTBAR, Strategy.DEFAULT, 0.05);
    vLastAlert = 2;
    }
    //}}EFSWizard_Action_2

    //}}EFSWizard_Actions

  • #2
    88888accountant
    You cannot use the Formula Wizard to accomplish that task as it requires creating global variables which the Formula Wizard does not allow for. You will need to write the necessary logic using the Editor
    You can find an example of the required logic for profit targets (not based on an indicator) in the Back Testing Tutorial 2. See also this thread for some other examples
    Alex

    Comment

    Working...
    X