Announcement

Collapse
No announcement yet.

Strategy Function Arguments

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

  • Strategy Function Arguments

    Can a value be added to or subtracted from Strategy arguments? For example;

    var vSpread = .10;

    Strategy.doLong("Long", Strategy.CLOSE + vSpread, Strategy.THISBAR);

    To properly represet buy orders which take the offer and sell orders which hit the bid, the script needs to account for the spread. To do that, can the value returned to the backtester by the Strategy.CLOSE argument be affected by inserting "+ vSpread" or "- vSpread"?

  • #2
    Lancer
    I believe that in that case you would need to use Strategy.STOP or Strategy.LIMIT and then define the fill price
    Alex

    Comment


    • #3
      I think using .STOP or .LIMIT requires a certain price, not an increment relative to OHLC of a bar. If instead of a certain price, the argument "close() + vSpread" could be used with .STOP and .LIMIT, then that would be something to try.

      That gets me back to my original question... can modifiers such as "+ .10" or "- vSpread" be added to affect Strategy argument values returned to the backtester?

      Comment


      • #4
        Lancer
        Unless I misunderstood what you said then Strategy.STOP (or LIMIT) can be used with that argument. Try the following sample
        Alex

        PHP Code:
        function preMain() {
            
        setPriceStudy(true);
            
        setStudyTitle("Strategy.STOP");
            
        setShowCursorLabel(false);
              
        }
        function 
        main() {

        var 
        vSpread 0.25;

        if((
        getHour()*100)+getMinute()==1000 && !Strategy.isLong()){
        Strategy.doLong("Long",Strategy.STOP,Strategy.THISBAR,null,close(-1)+vSpread);
        setBarBgColor(Color.yellow);
        }

        return;

        Comment

        Working...
        X