How to code? - page 187

 

Yes, I want to make 3 steps

Exemple:

Reach 15 and come back 10

Reach 30 and come back 15

Reach 45 and come back 15

Or close at stop loss.

I will take a pic and try to explain better.

 
fosgate_r:
This is something new to me.

So, the losing trade closing always need to wait until it bounce back right?

How about if it doen't bounceback?

Will we close at the intial SL?

Thanks by now, I already made it, now trying to optimize to get good results with this loss protection.

 

I"m trying to find info on plotting a line, just like the RSI indicator for example..I have two numbers I want to plot as lines on the same indicator

I know it will involve an array of some sort but I'm not having luck figuring out what group of code will make this happen.

 

indicator buffer

SPACECHIMP:
I"m trying to find info on plotting a line, just like the RSI indicator for example..I have two numbers I want to plot as lines on the same indicator I know it will involve an array of some sort but I'm not having luck figuring out what group of code will make this happen.

Please read this article

MQL4 Language for Newbies. Custom Indicators (Part 1) - MQL4 Articles

 
smb1970:
Hi Folks,

I don't know if anyone is familiar with Forex Made-EZ by George Smith.

I'm currently reviewing his work and wondered if anyone has coded an indicator for the Oscar oscillator he uses?

The formula is

let A = the highest high of the last eight bars (including this one)

let B = the lowest low of the past eight bars (including this one)

let C = current bars closing price

let X = the previous oscillator figure (Oscar)

Today's "rough" oscillator equals (C-B) divided by (A-B) times 100.

Next we "smooth" our rough number (let's call it Y) like this:

Final oscillator number = ((X divided by 3) times 2), plus (Y divided by 3).

If anyone has either coded this or can code this it would be highly appreciated.

Regards Steve

I've had a go at coding this myself. Could anybody comment on whether this does what I think it does. The values don't quite seem to tally to what they do if I manually calculate the figures. Also, it only starts from the time the indicator is placed. I'd like it to show the historic values as well.

#property indicator_separate_window

#property indicator_buffers 1

#property indicator_color1 Red

//---- buffers

double ExtMapBuffer1[];

//+------------------------------------------------------------------+

//| Custom indicator initialization function |

//+------------------------------------------------------------------+

int init()

{

//---- indicators

SetIndexStyle(0,DRAW_LINE);

SetIndexBuffer(0,ExtMapBuffer1);

string short_name = "Oscar Indicator";

IndicatorShortName(short_name);

//----

return(1);

}

//+------------------------------------------------------------------+

//| Custor indicator deinitialization function |

//+------------------------------------------------------------------+

int deinit()

{

return(0);

}

//+------------------------------------------------------------------+

//| Custom indicator iteration function |

//+------------------------------------------------------------------+

int start()

{

int 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 pos=Bars-counted_bars;

//---- main calculation loop

double x;

x=50;

while(pos>=0)

{

double a, b, c, y, osc;

//let A = the highest high of the last eight bars (including this one)

a=High;

//let B = the lowest low of the past eight bars (including this one)

b=Low;

//let C = current bars closing price

c = Close[pos];

//let X = the previous oscillator figure (Oscar)

//Today's "rough" oscillator equals (C-B) divided by (A-B) times 100.

y=((c-b)/(a-b))*100;

//Next we "smooth" our rough number (let's call it Y) like this:

//Final oscillator number = ((X divided by 3) times 2), plus (Y divided by 3).

osc=((x/3)*2)+(y/3);

ExtMapBuffer1[pos]= osc ;

pos--;

}

return(0);

}

Any help gratefully received.

Thanks Steve

 

Ask... Mode_trades

hi, can anyone give example for MODE_TRADES use for?

Thanks.

 

To smb1970 - this is it :

//+------------------------------------------------------------------+

//+------------------------------------------------------------------+

#property indicator_separate_window

#property indicator_buffers 1

#property indicator_color1 Red

#property indicator_maximum 100

#property indicator_minimum 0

//

//

//

//

//

extern int OscPeriod = 8;

extern int OscPrice = PRICE_CLOSE;

double oscBuffer[];

//+------------------------------------------------------------------+

//| |

//+------------------------------------------------------------------+

//

//

//

//

//

int init()

{

SetIndexBuffer(0,oscBuffer);

IndicatorShortName("Osc ("+OscPeriod+")");

return(0);

}

int deinit() { return(0); }

int start()

{

int counted_bars=IndicatorCounted();

int i,limit;

if(counted_bars<0) return(-1);

if(counted_bars>0) counted_bars--;

limit=Bars-counted_bars;

//

//

//

//

//

for(i=limit; i>=0; i--)

{

double price = iMA(NULL,0,1,0,MODE_SMA,OscPrice,i);

double high = High[ArrayMaximum(High,OscPeriod,i)];

double low = Low[ArrayMinimum(Low,OscPeriod,i)];

//

//

//

//

//

if (high!=low)

double raw = 100.00*(price-low)/(high-low);

else raw = 0.00;

oscBuffer= oscBuffer*2.0/3.0 + raw/3.0;

}

return(0);

}

But, take a look at the picture too : upper is "Oscar" lower is Ema(5) of stochastic(8), or to make it even simpler, on the bottom is Stochastic(8,5,1) with signal line set to exponential. So "Oscar" is simply a signal line of the stochastic

Files:
oscar.gif  21 kb
 

Thanks!

Thanks mladen, not only is that very useful, it's also very revealing!

 

NewB in need of some help with coding :-(

Hi All,

I'm in need of some disparate help here . I've got some code that will look for an agreement between different indicators. Once they all agree I want a way for the trades to enter in the way I described it in the chart images. So far I can enter the 1st "Buy" trade but it doesn't enter just 1 trade....it's entering up to 8 trades. And then, if the market goes against me I enter a "contingency trade" where I'm buy/selling again despite that its going against me. I would greatly appreciate if someone could show me what the correct code should look like

Not sure if these images will show but just in case I also have them as attachments.

Here is my flawed code that is supposed to execute the trade...

while (execute_trade ==5)

{if ( OrdersTotal() == buy_trade1 ) //buy_trade1 = 1...this stops it after 1 order have been placed...but doesnt work yet

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point);

execute_trade=0;

if(OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES))

Print("My ticket is: " , ticket);

{

buy1 = OrderOpenPrice(); //taking the 1st order's price and pushing it into this variable

// Comment("order #1 open price is ", OrderOpenPrice() + " " + buy1 + " less than " + (buy1-0.0030));

if (buy1 >= (buy1-0.0030))

{

//if ( OrdersTotal() <= buy_trade1 ) //this stops it after 1 order have been placed.

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point);

//execute_trade=0;

}

} else

Print("OrderSelect returned the error of ",GetLastError());

}

 

NewB in need of some help with coding

Hi All,

I'm in need of some disparate help here. I've got some code that will look for an agreement between different indicators. Once they all agree I want a way for the trades to enter in the way I described it in the chart images. So far I can enter the 1st "Buy" trade but it doesn't enter just 1 trade....it's entering up to 8 trades. And then, if the market goes against me I enter a "contingency trade" where I'm buy/selling again despite that its going against me.I would greatly appreciate if someone could show me what the correct code should look like

Not sure if these images will show but just in case I also have them as attachments.

Pic 1

Pic 2

Here is my flawed code that is supposed to execute the trade...

while (execute_trade ==5)

{if ( OrdersTotal() == buy_trade1 ) //buy_trade1 = 1...this stops it after 1 order have been placed...but doesnt work yet

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+ TakeProfit*Point);

execute_trade=0;

if(OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES))

Print("My ticket is: " , ticket);

{

buy1 = OrderOpenPrice(); //taking the 1st order's price and pushing it into this variable

// Comment("order #1 open price is ", OrderOpenPrice() + " " + buy1 + " less than " + (buy1-0.0030));

if (buy1 >= (buy1-0.0030))

{

//if ( OrdersTotal() <= buy_trade1 ) //this stops it after 1 order have been placed.

ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+ TakeProfit*Point);

//execute_trade=0;

}

}

else

Print("OrderSelect returned the error of ",GetLastError());

}