learning mql5

Hayseed, do you actively use this ATR convention? And is this something you began using in futures as opposed to your forex trades?

Last question, are you starting this at the Forex market turnover (5pm est)?
//-----

lol...... yes in a way......, but don't expect me to remember what much about my thoughts back then......

ideas just come to me..... i try to code them..... discard them...... then move to the next idea.......

it was just to visualize the best % of the daily atr to target and risk...... ended up using 0.4%......

such as, yesterdays values......

mym 0.4% was 188 points...... 2 mym contracts would be 188$ ......

mes 0.4% was 25 points ..... 1 mes contract would be 125$......

mnq 0.4% was 90 points....... 1 mnq contract would be 180$......

m2k 0.4 was 9 points...... 1 m2k contract would be 45$......

188+125+180+45........ so your risking 538 to make 538 per day......

even using those small contract sizes, the risk is too high on a 150k account...... on 300k, the risk would be ok.....

200$ a day is plenty for me......h

//-------

Screenshot 2025-07-14 222742.png

//-------


Screenshot 2025-07-14 222628.png

//------
 
//-----

lol...... yes in a way......, but don't expect me to remember what much about my thoughts back then......

ideas just come to me..... i try to code them..... discard them...... then move to the next idea.......

it was just to visualize the best % of the daily atr to target and risk...... ended up using 0.4%......

such as, yesterdays values......

mym 0.4% was 188 points...... 2 mym contracts would be 188$ ......

mes 0.4% was 25 points ..... 1 mes contract would be 125$......

mnq 0.4% was 90 points....... 1 mnq contract would be 180$......

m2k 0.4 was 9 points...... 1 m2k contract would be 45$......

188+125+180+45........ so your risking 538 to make 538 per day......

even using those small contract sizes, the risk is too high on a 150k account...... on 300k, the risk would be ok.....

200$ a day is plenty for me......h

//-------

View attachment 33580

//-------


View attachment 33581

//------
If that limit order triggers, the trailing order on the PSAR - is that going to hav a pt of it's own, or would it trigger an adjustment to your overall PT currently in place?
 
If that limit order triggers, the trailing order on the PSAR - is that going to hav a pt of it's own, or would it trigger an adjustment to your overall PT currently in place?
//---

most often it will just follow what is in place..... it will not adjust the price lower or higher...... it will only adjust the $ amount at the target.....

those limit orders were not trailing and had nothing to do with the psar...... but that was a good catch on your part......

i had them as a 'just in case' spike down...... felt the friday close gap would hold......

once/if the asian session orders close, i'll just trade the mym...... very seldom trade the mnq between 5 and 10 am......

during the new york session i can lose in 1 minute what it took me the prior 1000 minutes to make.....h
//-----

Screenshot 2025-07-15 061236.png
 
cpi in 5 minutes...... have no clue as to what the actual numbers will be...... even if i did, it probably would not benefit me any...... tend to lose trading news.....

just watch.....h
//------

Screenshot 2025-07-15 072122.png

//-----

Screenshot 2025-07-15 072219.png
 
//----

conditional bar color with minimum number in agreement..... majority with a minimum......

need to include a atr override veto......

possible 4th color....... h

//-----


MQL5:
input int minimum = 8;
 
//--- indicator buffers
 
int OnCalculate(const int rates_total,
 
 
 
 
      //--- aqua
      if(  ((abuffer[i] > abuffer[i-1]) + (bbuffer[i] > bbuffer[i-1]) + (cbuffer[i] > cbuffer[i-1]) + (dbuffer[i] > dbuffer[i-1]) + (ebuffer[i] > ebuffer[i-1]) + (fbuffer[i] > fbuffer[i-1]) + (gbuffer[i] > gbuffer[i-1]) + (hbuffer[i] > hbuffer[i-1]) + (ibuffer[i] > ibuffer[i-1])) >= minimum)    ExtColorBuffer[i] = 0.0;
 
      //--- magenta
      if(  ((abuffer[i] < abuffer[i-1]) + (bbuffer[i] < bbuffer[i-1]) + (cbuffer[i] < cbuffer[i-1]) + (dbuffer[i] < dbuffer[i-1]) + (ebuffer[i] < ebuffer[i-1]) + (fbuffer[i] < fbuffer[i-1]) + (gbuffer[i] < gbuffer[i-1]) + (hbuffer[i] < hbuffer[i-1]) + (ibuffer[i] < ibuffer[i-1])) >= minimum)    ExtColorBuffer[i] = 1.0;
Do you mind sharing how you structre the buffers in OnInit and properties to get these conditional bars?

i am trying my bst to understand the documentation, but i am lost.

I created 5 buffers (one for OHLC, and one for color). I've tried having all my colors in an array, and indexing them (what it looks like the documentation does), but that doesn't seem to work:
 
Do you mind sharing how you structre the buffers in OnInit and properties to get these conditional bars?
//----- if then...... are very important words ......

for those of us without formal training, learning mq5 will be very time consuming......

designing a manual trading system based on the chart below might more productive.......

perhaps time better spent......h
//------



MQL5:
void OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,opens,INDICATOR_DATA);
   SetIndexBuffer(1,highs,INDICATOR_DATA);
   SetIndexBuffer(2,lows,INDICATOR_DATA);
   SetIndexBuffer(3,closes,INDICATOR_DATA);
 
   SetIndexBuffer(4,colors,INDICATOR_COLOR_INDEX);
 
   SetIndexBuffer(5,abuffer,INDICATOR_CALCULATIONS);
   SetIndexBuffer(6,bbuffer,INDICATOR_CALCULATIONS);
   SetIndexBuffer(7,cbuffer,INDICATOR_CALCULATIONS);
   SetIndexBuffer(8,dbuffer,INDICATOR_CALCULATIONS);
   SetIndexBuffer(9,ebuffer,INDICATOR_CALCULATIONS);
 
//--- get handles  35 total
 
 ahandle  =  iCustom(_Symbol,Period(),"jfatl");                     
 bhandle  =  iCustom(_Symbol,Period(),"jjma");                         
 chandle  =  iCustom(_Symbol,Period(),"Coppock");                         
 dhandle  =  iCustom(_Symbol,Period(),"alma");                   
 ehandle  =  iTEMA(_Symbol,Period(),20,0,PRICE_CLOSE);                       
 
 
}

//------

Screenshot 2025-07-16 054417.png
 
SetIndexBuffer(0,opens,INDICATOR_DATA);
SetIndexBuffer(1,highs,INDICATOR_DATA);
SetIndexBuffer(2,lows,INDICATOR_DATA);
SetIndexBuffer(3,closes,INDICATOR_DATA);

SetIndexBuffer(4,colors,INDICATOR_COLOR_INDEX);


this is how I have it I as well, in my OnInit. is ''color" a list of your colors, or is

MQL5:
#property indicator_color1  clrGray,clrDarkBlue,clrOrchid,clrAqua,clrMagenta,clrBlue,clrRed,clrYellow

all that is needed for your bars to change color and for your ExtIndexBuffer to know what 2.0 or 1.0 is? The below is how I have been trying to track rising and falling MAs and the colors, but they don't seem to want to work. I am using iBarshift as this is is not a scan for a dash right now, just an indicator that will live on a chart.

the handles are established in OnInit. Also is ArraySetAsSeries. I don't have any "indicator buffers", but I do have a buffer established for each indicator and timeframe that I am trying to compare.

Do you see where I am going wrong?

MQL5:
int OnCalculate(const int32_t rates_total,
                const int32_t 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 int32_t &spread[])
  {
//---
 
 
   int limit = rates_total - prev_calculated;
   for(int i = MathMin(limit + 1, rates_total - 1); i >= 0 && !IsStopped(); i--)
     {
 
      bar15 = 1 + iBarShift(_Symbol, PERIOD_M15, time[i]);
      bar30 = 1 + iBarShift(_Symbol, PERIOD_M30, time[i]);
      bar60 =  1 + iBarShift(_Symbol, PERIOD_H1, time[i]);
      bar240 = 1 + iBarShift(_Symbol, PERIOD_H4, time[i]);
 
      CopyBuffer(a15,0,bar15,2,alma15);
      CopyBuffer(a30,0,bar30,2,alma30);
      CopyBuffer(a60,0,bar60,2,alma60);
      CopyBuffer(a240,0,bar240,2,alma240);
 
      CopyBuffer(t1015,0,bar15,2,tsr1015);
      CopyBuffer(t1030,0,bar30,2,tsr1030);
      CopyBuffer(t1060,0,bar60,2,tsr1060);
      CopyBuffer(t10240,0,bar240,2,tsr10240);
 
      CopyBuffer(t2015,0,bar15,2,tsr2015);
      CopyBuffer(t2030,0,bar30,2,tsr2030);
      CopyBuffer(t2060,0,bar60,2,tsr2060);
      CopyBuffer(t20240,0,bar240,2,tsr20240);
 
      a15_1 = alma15[0];
      a15_2 = alma15[1];
      a30_1= alma30[0];
      a30_2=  alma30[1];
      a60_1= alma60[0];
      a60_2 =  alma60[1];
      a240_1 =alma240[0];
      a240_2 =  alma240[1];
 
      t1015_2 = tsr1015[1];
      t1015_1 = tsr1015[0];
      t1030_2 = tsr1030[1];
      t1030_1 = tsr1030[0];
      t1060_2 =  tsr1060[1];
      t1060_1 = tsr1060[0];
      t10240_2 =  tsr10240[1];
      t10240_1 = tsr10240[0];
 
      t2015_2 = tsr2015[1];
      t2015_1 = tsr2015[0];
      t2030_2 = tsr2030[1];
      t2030_1 = tsr2030[0];
      t2060_2 = tsr2060[1];
      t2060_1 = tsr2060[0];
      t20240_2 = tsr20240[1];
      t20240_1 = tsr20240[0];
 
 
      score = 0;
 
      dxn = clrGray;
 
      if(a15_1 > a15_2 && t1015_1 > t1015_2 && t2015_1 > t2015_2)
        {
         score += 10;
        }
      if(a30_1 > a30_2 && t1030_1 > t1030_2 && t2030_1 > t2030_2)
        {
         score += 10;
        }
      if(a60_1 > a60_2 && t1060_1 > t1060_2 && t2060_1 > t2060_2)
        {
         score += 10;
        }
      if(a240_1 > a240_2 && t10240_1 > t10240_2 && t20240_1 > t20240_2)
        {
         score += 10;
        }
 
      if(a15_1 < a15_2 && t1015_1 < t1015_2 && t2015_1 < t2015_2)
        {
         score += -10;
        }
      if(a30_1 < a30_2 && t1030_1 < t1030_2 && t2030_1 < t2030_2)
        {
         score += -10;
        }
      if(a60_1 < a60_2 && t1060_1 < t1060_2 && t2060_1 < t2060_2)
        {
         score += -10;
        }
      if(a240_1 < a240_2 && t10240_1 < t10240_2 && t20240_1 < t20240_2)
        {
         score += -10;
        }
 
      color_index = 2;
 
      if(MathAbs(score) > minimum && score > 0)
        {
         dxn = clrAqua;
        }
      if(MathAbs(score) < minimum && score < 0)
        {
         dxn = clrMagenta;
        }
      if(dxn == clrMagenta)
        {
         color_index = 0;
        }
      if(dxn == clrAqua)
        {
         color_index = 1;
        }
 
      ColorBarsBuffer1[i] = iOpen(_Symbol,PERIOD_CURRENT,i);
      ColorBarsBuffer2[i] = iHigh(_Symbol,PERIOD_CURRENT,i);
      ColorBarsBuffer3[i] = iLow(_Symbol,PERIOD_CURRENT,i);
      ColorBarsBuffer4[i] = iClose(_Symbol,PERIOD_CURRENT,i);
      ColorBarsColors[i]  = colors[color_index];
 
     }
//--- return value of prev_calculated for next call
   return(rates_total);
 
  }



//----- if then...... are very important words ......

for those of us without formal training, learning mq5 will be very time consuming......

I am curious what you are meaning here? A time consuming challenge has never seemed to disuade you if the challenge was worthy... such as pursuing futures.
 
I am curious what you are meaning here? A time consuming challenge has never seemed to disuade you if the challenge was worthy... such as pursuing futures.
//----

my moving to futures was a combination of oanda and metaquotes pulling mq4 from prop firms...... if i had my choice, i would still be trading forex with prop firms using mq4 only...... and trading 0.01 lots.......

i have the free time to learn mq5..... are you sure you do.......h

//----

ibarshift.......
 
Do you know why my code might be drawing 3 lines when I try to draw vertical lines with iBarShift?

I learned that it seems I cannot use time or Time in my iBarShift like I could in mql4. So I have since stated using iTime(_Symbol, PERIOD_CURRENT,i);

I then use the bar shift int to draw 3 values into my alma buffer. I then search for pivots and attempt to draw a line.

Theoretically, I understand that on an M5, there will be technically 3 bars where the alma pivot is true. However, I seem to recall MQL4, using the same conventions I used in this, would only print a single vertical bar. The only thing I can think is that I'd need to implement Bool logic. to avoid all 3 lines being drawn, but I don't think that sounds right.

Am i missing something that is keeping this code from running how I intend (green and red lines at Alma pivots - a singel line that is shifted to wherever the pivot occurred on the 15 minute timeframe, whether the current tf is 1,2,5 etc.


Code:
   for(int i = 50; i >=0 && !IsStopped(); i--)
     {

      Print("===========================================================");
      Print("==================== Bar ", i, "  =======================");
      dxn = clrNONE;
      score = 0;

      bar15 = iBarShift(_Symbol, PERIOD_M15, iTime(_Symbol,PERIOD_CURRENT,i));
      CopyBuffer(a15,0,bar15,3,alma15);

      Print(alma15[0]);
      Print(alma15[1]);
      Print(alma15[2]);
      //return true;
      a15_1 = alma15[0];
      a15_2 = alma15[1];
      a15_3 = alma15[2];

      if(a15_2 > a15_1 && a15_2 > a15_3)
        {
         DrawVerticalLine(i,clrRed);
        }

      if(a15_2 < a15_1 && a15_2 < a15_3)
        {
         DrawVerticalLine(i,clrGreen);
        }

1752732730120.png


I have been trying to figure this out for hours...
 
//----

my moving to futures was a combination of oanda and metaquotes pulling mq4 from prop firms...... if i had my choice, i would still be trading forex with prop firms using mq4 only...... and trading 0.01 lots.......

i have the free time to learn mq5..... are you sure you do.......h

//----

ibarshift.......
Well, I suppose I have been making time. Baby 5 is due in about 3 weeks. Next oldest kiddo is 18 months. I tell my wife I can’t wait because I will have time to get so much done while on leave.

She laughs and says, “you mean helping me right?”

Of course that’s what I mean, but I love giving her a hard time in jest.

I gave up on trading many years ago after doing what many do- chasing this YT channel and that. It became clear that the real successful traders were not the ones with 1MM subscribers.

Learned MQL4 about 4 or 5 years ago. Boy did I miss some trending markets over those years!Put it down because my work picked up and I stayed pretty engrossed in it. I made the time. Probably sacrificed in other areas m. No, definitely did. Sleep being the biggest, as I try to stay off the pc while the boys are all awake.

Then I came back. Got the itch. Like the idea of futures, and figured I’d pick up MQL5. In truth, I’ve always wanted to because I read it can handle more processing power. Back when all my dashboards locked up every new bar, I thought MT5 was the way.

My latest endeavor is simply using a DLL or OANDA’s feed to pump it all into python and analyse counts and signals completely separate from the terminal.

Worst case is I’m learning a new skill. Maybe I can even get into programming. Who knows.
 
Baby 5 is due in about 3 weeks. Maybe I can even get into programming. Who knows.
//------

priorities.......

gabe and chris today were talking about their attempt at building a api that will place trades on topstepx..........

that's the first time i've every saw someone thinking in terms of counts......

he mentioned knowing the time window of a signal in minutes........ they are the very early stages of development.......

mq5 can do the same thing......

what follows a red 13.......h

//------

Screenshot 2025-07-17 133705.png

//-------

 
tenary operator ?: is a shortcut meant to simplify code....... appears to be a very mandatory if/else..... returns only expressions contained in itself...... so it will override the default setting......

do not see a way for cascading thru additional conditions.....

when using ?: , advanced conditional color selections do not appear possible......h

//---

MQL5:
      for(int t = 0; t < 7; t++)                         
      {
       string symbol = sym[r]+tfs[t];
 
 
      bool himabuy  = (GlobalVariableGet(symbol+"50ma") ==  10) && (GlobalVariableGet(symbol+"100ma") ==  10) && (GlobalVariableGet(symbol+"200ma") ==  10);
 
      bool himasell = (GlobalVariableGet(symbol+"50ma") == -10) && (GlobalVariableGet(symbol+"100ma") == -10) && (GlobalVariableGet(symbol+"200ma") == -10);
 
 
 
       //color jjmaclr = clrYellow;   // if a false, b false, c false,,,,,  jjmaclr remains yellow     
 
         color jjmaclr     = (GlobalVariableGet(symbol+"jjma") == 10)?clrLime:clrRed;  // ?: appears mandatory lime or red
 
       //if(GlobalVariableGet(symbol+"jjma") ==  10)              {jjmaclr = clrLime;}
 
       //if(GlobalVariableGet(symbol+"jjma") == -10)              {jjmaclr = clrRed;} 
 
       if(himabuy  && GlobalVariableGet(symbol+"jjma") ==  20) {jjmaclr = clrBlue;}
 
       if(himasell && GlobalVariableGet(symbol+"jjma") == -20) {jjmaclr = clrMagenta;} 
 
 
 
       Display(symbol+"jjma",  200+(t*20)+(r*300), 60);    //  +(r*100)  60+(rr*30));
       ObjectSetText(symbol+"jjma", "Û",6,"Terminal", jjmaclr);
       ObjectSetString(0, symbol+"jjma", OBJPROP_TOOLTIP, symbol + " if(jjmas[1] > jjmas[2])");       
//-----