Announcement

Collapse
No announcement yet.

im a bit rusty and i need some help : /

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

  • im a bit rusty and i need some help : /

    hey guys, i havent been here in a while but ive got a renewed interest in writing some programs to backtest, but im a bit rusty and my code isnt working quite right, everything appears to be working EXCEPT the doLong and doShort events, and i dont know why, could someone take a look and help me out please?



    PHP Code:
    var ValidTime false
    var Counter 0
    var 0
    var 0
    var State 0
    function preMain() {
        
    setPriceStudy(true);
        
    setColorPriceBars(true);
        
    setStudyTitle("4 hours");
        
    setCursorLabelName("4 hours",0)
        
    setPlotType(PLOTTYPE_FLATLINES0)
    }

    function 
    main() {

    //ONLY ALLOWS THE EFS TO ENTER A TRADE BETWEEN 22:00 AND 03:59
    ValidTime false
    if (getHour() >= 22ValidTime true
    if (getHour() < 4ValidTime true

    // DEFINES "H" AS THE GREEN BAR ON THE CHART, AND "L" AS THE RED BAR ON THE CHART
    if (getHour() >= 18 && getHour() < 22) {
        if (
    high() > high(-1)) high() 
            else 
    high(-1)
        if (
    low() < low(-1)) low() 
            else 
    low(-1)
    }

    //THIS IS JUST DRAWING THE LINES ON THE CHART
    if (getHour() == 20) {
        
    drawLineRelative(0H3HPS_SOLID4Color.RGB(0,128,0), Counter 6)
        
    drawLineRelative(0L3LPS_SOLID4Color.RGB(128,0,0), Counter 7)
        
    drawLineRelative(-1H, -1LPS_SOLID4Color.RGB(255,0,255), Counter)
        
    drawLineRelative(0H0LPS_SOLID4Color.RGB(255,0,255), Counter 1)
        
    drawLineRelative(-1H0HPS_SOLID4Color.RGB(255,0,255), Counter 2)
        
    drawLineRelative(-1L0LPS_SOLID4Color.RGB(255,0,255), Counter 3)
        
    drawLineRelative(-1H0LPS_SOLID4Color.RGB(255,0,255), Counter 4)
        
    drawLineRelative(-1L0HPS_SOLID4Color.RGB(255,0,255), Counter 5)
        
    Counter Counter 8
    }

    //ENTERS TRADE AT THE PRICE "H" OR "L" WHEN THE PRICE CROSSES ONE OF THE TWO LINES WITHIN "VALIDTIME"
    if(ValidTime == true) {
        if (
    high() >= State 1
        
    if (high() >= Strategy.doLong(""Strategy.LIMITStrategy.THISBARStrategy.DEFAULT, H)
        if (
    low() <= State = -1
        
    if (low() <= Strategy.doShort(""Strategy.LIMITStrategy.THISBARStrategy.DEFAULT, L)
    }

    //AFTER THE VALID TIME IS OVER, THE TRADE CLOSES
    if (ValidTime == false) {
        if (
    State == 1) {
            
    State 0
            Strategy
    .doSell(""Strategy.LIMITStrategy.THISBARStrategy.ALLclose())
        }
        if (
    State == -1) {
            
    State 0
            Strategy
    .doCover(""Strategy.LIMITStrategy.THISBARStrategy.ALLclose())
        }
    }

    //THIS COLORS THE BAR GREEN IF IT IS CURRENTLY LONG AND RED IF IT IS CURRENTLY SHORT
    setPriceBarColor(Color.RGB(128,128,128))
    if (
    Strategy.isLong == truesetPriceBarColor(Color.RGB(0,255,0))
    if (
    Strategy.isShort == truesetPriceBarColor(Color.RGB(255,0,0))


    Last edited by kalzenith; 08-11-2009, 08:31 AM.

  • #2
    The problems appear to be near the end of your code..

    //AFTER THE VALID TIME IS OVER, THE TRADE CLOSES
    if (ValidTime == false) {
    if (State == 1) {
    State = 0;
    Strategy.doSell("", Strategy.LIMIT, Strategy.THISBAR, Strategy.ALL, close());
    if (State == -1) {
    State = 0;
    Strategy.doCover("", Strategy.LIMIT, Strategy.THISBAR, Strategy.ALL, Close())
    }

    //THIS COLORS THE BAR GREEN IF IT IS CURRENTLY LONG AND RED IF IT IS CURRENTLY SHORT
    setPriceBarColor(Color.RGB(128,128,128))
    if (Strategy.isLong()) setPriceBarColor(Color.RGB(0,255,0))
    if (Strategy.isShort()) setPriceBarColor(Color.RGB(255,0,0))

    }


    Your "Close position" code was not correct. You were setting the "State" variable to ZERO, then checking it again to see if you could close out the position. This won't fly in EFS.

    Please try these changes and let me know if they helped?
    Brad Matheny
    eSignal Solution Provider since 2000

    Comment


    • #3
      wow, that seems rather obvious now that you point it out, thanks, ive made the changes and the backtest is giving results now. But there are a couple problems still, its still not coloring the bars on the chart when its in a trade, and the backtest is saying there are an average of 2.5 bars between trades when there should be a minimum of 9 since ive restricted the times it can trade

      you missed a couple closing braces, so this is exactly what i replaced it with

      PHP Code:
      //AFTER THE VALID TIME IS OVER, THE TRADE CLOSES
      if (ValidTime == false) {
          if (
      State == 1) {
              
      State 0
              Strategy
      .doSell(""Strategy.LIMITStrategy.THISBARStrategy.ALLclose())
          }
          if (
      State == -1) {
              
      State 0
              Strategy
      .doCover(""Strategy.LIMITStrategy.THISBARStrategy.ALLclose())
          }

      Last edited by kalzenith; 08-11-2009, 08:30 AM.

      Comment


      • #4
        i figured out why it wasnt coloring the bars, i put Strategy.isLong == true, not Strategy.isLong() == true

        Comment

        Working...
        X