Custom Indicator - HLine Tweaks

 

Hi,

I've been writing a custom indicator which identifies swing points, then draws a horizontal line 'x' pips above the last swing high ('highline') and 'x' pips below the last swing low ('lowline'). The distance between the 2 lines is calculated, and then another horizontal line is created that distance above/below 'highline' and 'lowline' (I hope that makes sense!).

I am looking for some pointers on how to achieve 2 more features:

  1. The horizontal lines extend all the way to the right-hand side, but because I use chart shift I would like them to stop at the current bar... is that possible?
  2. I would like the option to manually move 'highline' and 'lowline' (rather than keep the automatic placement at the last swing points), and then the other lines to be automatically recalculated on the new distance between 'highline' and 'lowline'. Any tips on the best way to approach this would be very much appreciated!

Many thanks

 
Hline Goes all the way across. A Tline with ray=false, only goes from your start to your end (update the end each bar.)
void HLine(string name, double P0, color clr){          #define WINDOW_MAIN 0
    /**/ if (ObjectMove( name, 0, Time[0], P0 )){}
    else if(!ObjectCreate( name, OBJ_HLINE, WINDOW_MAIN, Time[0], P0 ))
        Alert("ObjectCreate(",name,",HLINE) failed: ", GetLastError() );
    /**/ if (!ObjectSet(name, OBJPROP_COLOR, clr )) // Allow color change
        Alert("ObjectSet(", name, ",Color) [1] failed: ", GetLastError() );
}
void TLine( string name, datetime T0, double P0, datetime T1, double P1
          , color clr, bool ray=false ){
    /**/ if(ObjectMove( name, 0, T0, P0 ))      ObjectMove(name, 1, T1, P1);
    else if(!ObjectCreate( name, OBJ_TREND, WINDOW_MAIN, T0, P0, T1, P1 ))
        Alert("ObjectCreate(",name,",TREND) failed: ", GetLastError() );
    else if (!ObjectSet( name, OBJPROP_RAY, ray ))
        Alert("ObjectSet(", name, ",Ray) failed: ", GetLastError());
    /**/ if (!ObjectSet(name, OBJPROP_COLOR, clr )) // Allow color change
        Alert("ObjectSet(", name, ",Color) [2] failed: ", GetLastError() );
}
 

Thank you very much for the reply, but I think I may have to take it back a step as I am still very much learning the language!

Currently, the following section draws one of the horizontal lines successfully:

            if (isSwingLowBar(i))
               {
                  SwingLow_Buffer[i] = Low[i]-ArrowGap*Point;
                  SwingHigh_Buffer[i] = EMPTY_VALUE;
                  double LowLineLevel = Low[i]-LineGap*Point;
                  ObjectDelete("LowLine");
                  ObjectCreate("LowLine",OBJ_HLINE,0,0,LowLineLevel);
                  ObjectSet("LowLine",OBJPROP_COLOR,LowLineColor);
                  ObjectSet("LowLine",OBJPROP_STYLE,STYLE_DOT);
                  ObjectSet("LowLine",OBJPROP_WIDTH,1);
               }

So if I change that to OBJ_TREND and define what (I think!) is a start and an end, and set ray to false, it will not display anything:

            if (isSwingLowBar(i))
               {
                  SwingLow_Buffer[i] = Low[i]-ArrowGap*Point;
                  SwingHigh_Buffer[i] = EMPTY_VALUE;
                  double LowLineLevel = Low[i]-LineGap*Point;
                  ObjectDelete("LowLine");
                  ObjectCreate("LowLine",OBJ_TREND,Time[20],LowLineLevel,Time[0],LowLineLevel);
                  ObjectSet("LowLine",OBJPROP_RAY,false);
                  ObjectSet("LowLine",OBJPROP_COLOR,LowLineColor);
                  ObjectSet("LowLine",OBJPROP_STYLE,STYLE_DOT);
                  ObjectSet("LowLine",OBJPROP_WIDTH,1);
               }

Any pointers on what is going wrong would be great - I know my code is verbose and lacks finesse, but I'm trying to understand what I'm writing rather than copy/paste!