Rating: Empty Star Empty Star Empty Star Empty Star Empty Star
Help with indicator

Member Since May 21, 2020  9 posts 123Randyfutures Oct 20 at 17:31
Can anyone review the code and explain the vertical lines that are drawn on the chart?

Here is the code:

#property strict
#property indicator_buffers 4
#property indicator_chart_window

input int InpATRperiod=14; // ATR Periods
input float InpRisk=1; // Risk Size %
input float InpSLfactor=1.5; // Stop Loss as a factor of ATR

input int InpFontSize=12; // Font size
input color InpColor=Red; // Color
input int InpBaseCorner=CORNER_RIGHT_UPPER; // Base Corner 0=UL,1=UR,2=LL,3=LR
input float InpFixedATR=0; // Fixed ATR points

string AccntC=AccountCurrency(); //Currency of Acount eg USD,GBP,EUR
string CounterC=StringSubstr(Symbol(),3,3); //The Count Currency eg GBPUSD is USD
string ExC=AccntC+CounterC; //Create the Pair for account eg USDGBP

double UpTicks[];
double DownTicks[];

double Diff[];
//| Custom indicator initialization function |
int OnInit()

//| Custom indicator iteration function |
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
   int i,counted_bars=IndicatorCounted();
//---- check for possible errors
   if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   int limit=Bars-counted_bars;

   for(i=0; i<limit; i++)
   double ExCRate=1; //Assume Account is same as counter so ExCRate=1
   AccntC=AccountCurrency(); //Currency of Acount eg USD,GBP,EUR
   CounterC=StringSubstr(Symbol(),3,3); //The Count Currency eg GBPUSD is USD
   ExC=AccntC+CounterC; //Create the Pair for account eg USDGBP
      ExCRate= MarketInfo(ExC,MODE_ASK); //Get the correct FX rate for the Account to Counter conversion
   if(ExCRate ==0) ExCRate=1.0;
   double ATRPoints=iATR(NULL,0,InpATRperiod,0); //Get the ATR in points to calc SL and TP
   double riskVAccntC=AccountEquity()*(InpRisk/100);
   double riskvalue=(ExCRate/1)*riskVAccntC; //Risk in Account Currency
   double slpoints=(ATRPoints*InpSLfactor); //Risk in Counter Currency
   double riskperpoint=(riskvalue/slpoints)*Point;
   double lotSize=riskperpoint; //Risk in currency per point
   int pipMult=10000;
   if(CounterC=='JPY') {
   double ATRpips=MathCeil(pipMult*ATRPoints);

    ObjectSetString(ChartID(),'textATR',OBJPROP_TEXT,StringFormat('ATR(%.0f):%.0f %s', InpATRperiod,ATRpips,'pips'));
          ObjectSetString(ChartID(),'textRISK',OBJPROP_TEXT,StringFormat('Risk %.1f%%:%.0f %s',InpRisk,riskVAccntC,AccntC));
           ObjectSetString(ChartID(),'textlotsize',OBJPROP_TEXT,StringFormat('Lot Size At 1.5 Of ATR :%.2f',lotSize));
   //ObjectSetString(ChartID(),'textBuyVolume',OBJPROP_TEXT,StringFormat('Buy Volume:%.2f',UpTicks[0]));
   ObjectSetString(ChartID(),'textBuyVolume',OBJPROP_TEXT,StringFormat('Buy Volume:%.2f',UpTicks[0]));
      ObjectSetString(ChartID(),'textSellVolume',OBJPROP_TEXT,StringFormat('Sell Volume:%.2f',DownTicks[0]));


//--- forced chart redraw

//--- return value of prev_calculated for next call
void OnDeinit(const int reason)
//Function to create a text field in the main Window
// Example call --- text_init(ChartID(),'textATR',1000,30,clrRed,12);
int text_init(const long current_chart_id,const string obj_label,const int x_dist,const int y_dist,const int text_color,const int font_size)

//--- creating label object (it does not have time/price coordinates)
      Print('Error: can't create label! code #',GetLastError());
//--- set distance property


Member Since Oct 09, 2020  18 posts Marlonsmith Nov 05 at 12:04
I think it’s a nice quote. You can first try it on your demo account and then on your live account.


Member Since Oct 15, 2020  42 posts Bladiminmunro Nov 07 at 11:09
I have been looking for an indicator that suits my trading style. I guess I have found the one.


Member Since Nov 07, 2020  9 posts Rogerwood465 Nov 26 at 07:20
Looks like a nice quote. If you are not sure about it, I suggest trying it on your demo account first.


Member Since Nov 05, 2020  11 posts Christopher332 17 Hours ago
You need to get in touch with a programmer who can tell you this. I am not that good at coding.

Please login to comment.
EURUSD 1.19577 GBPUSD 1.33574
USDJPY 104.406 USDCAD 1.29723







Twitter |  Facebook |  Site Map  |  Terms  |   Privacy Policy
©2020 Myfxbook Ltd. All Rights Reserved.
HIGH RISK WARNING: Foreign exchange trading carries a high level of risk that may not be suitable for all investors. Leverage creates additional risk and loss exposure. Before you decide to trade foreign exchange, carefully consider your investment objectives, experience level, and risk tolerance. You could lose some or all of your initial investment; do not invest money that you cannot afford to lose. Educate yourself on the risks associated with foreign exchange trading, and seek advice from an independent financial or tax advisor if you have any questions. Any data and information is provided 'as is' solely for informational purposes, and is not intended for trading purposes or advice. Past performance is not indicative of future results.