Coding help - page 405

 
Tomcat98:
Hi Mladen,

Here is what the loop says for those pending orders where Multi_Indic_00 is an oscillator and Up_Prime_00 is a define level.

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

//---- Check And Close If Order Type is Limit And Trend has Changed.

if(OrderType()==OP_BUYLIMIT)

if(( Multi_Indic_00 ) <= (Up_Prime_00 ))

{

_OrderDelete=OrderDelete(OrderTicket());

}

if(OrderType()==OP_SELLLIMIT)

if(( Multi_Indic_00 ) >= ( Down_Prime_00 ))

{

_OrderDelete=OrderDelete(OrderTicket());

}

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

Well nothing special....

Happy trading.

Sincerely.

Tomcat98

Tomcat98

What I would like to see is the for() loop statement. If you are having a for statement like this :

for (int i = 0; i < OrdersTotal(); i++)

then some orders will be missed if in the mean time some orders has been closed or deleted. On the other hand, if the for() loop goes like this :

for (int i = OrdersTotal()-1; i >= 0; i--)

then it will process all the orders

 

Mladen ,

Oh I see:

Here is it for the close process:

"

for(int i=0;i<OrdersTotal();i++)

{

if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;

if(OrderMagicNumber()!=MAGIC || OrderSymbol()!=Symbol()) continue;

"

Tomcat98

 
Tomcat98:
Mladen ,

Oh I see:

Here is it for the close process:

"

for(int i=0;i<OrdersTotal();i++)

{

if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;

if(OrderMagicNumber()!=MAGIC || OrderSymbol()!=Symbol()) continue;

"

Tomcat98

Tomcat98

Change the loop to

for(int i=OrdersTotal()-1;i>=0;i--)

and it should be OK

 

Mladen,

Bingo!

It now does exactly what I needed.

Thanks very much for your great help.

“People don't care how much you know until they know how much you care”

― Theodore Roosevelt

Sincerely.

Tomcat98

 
Tomcat98:
Mladen,

Bingo!

It now does exactly what I needed.

Thanks very much for your great help.

“People don't care how much you know until they know how much you care”

― Theodore Roosevelt

Sincerely.

Tomcat98

Happy coding

 

Hi Mladen, thanks for every thing, working good there now...

now i'm stuck with an indicator created that is not reloading so everytime a candle close i have to reload the indicator, can you help me fix this?? here is part of the code (is a trend indicator based on gaps simple idea, thank you:

#property copyright "Copyright © 2014 Daniel Luchinger"

#property link

#property strict

#property strict

#property indicator_chart_window

#property indicator_buffers 4

#property indicator_color1 clrLime

#property indicator_color2 clrRed

#property indicator_color3 clrMagenta

#property indicator_color4 clrCyan

#define BUY 1

#define SELL 2

double Buy[],

Sell[],

FirstBuy[],

FirstSell[];

int OnInit() {

SetIndexBuffer(0,FirstBuy);

SetIndexBuffer(1,FirstSell);

SetIndexBuffer(2,Buy);

SetIndexBuffer(3,Sell);

for(int i=0; i<4; i++) {

SetIndexStyle (i,DRAW_ARROW,STYLE_SOLID,2);}

SetIndexArrow (0,233);

SetIndexArrow (1,234);

SetIndexArrow (2,233);

SetIndexArrow (3,234);

return(INIT_SUCCEEDED);}

void OnDeinit(const int reason) {}

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[]) {

static int lastSignal=0;

for(int i=MathMin(rates_total-prev_calculated, rates_total-1); i>=0; i--) {

FirstBuy=FirstSell=Buy=Sell=EMPTY_VALUE;

datetime when=Time;

if((High-Close)<0) {

if(lastSignal==SELL) {

FirstBuy=Close;

SoundAlert(when,"Buy");}

lastSignal=BUY;}

if((Low-Close)>0){

if(lastSignal==BUY) {

FirstSell=Close;

SoundAlert(when,"Sell");}

lastSignal=SELL;}

}

return(rates_total);}

void SoundAlert(datetime i, string dir) {

static datetime lastAlert=0;

if(lastAlert!=i) {

Alert(StringFormat("%s signal on %s at %s",dir,Symbol(),TimeToStr(i)));

 
daniel1983:
Hi Mladen, thanks for every thing, working good there now...

now i'm stuck with an indicator created that is not reloading so everytime a candle close i have to reload the indicator, can you help me fix this?? here is part of the code (is a trend indicator based on gaps simple idea, thank you:

#property copyright "Copyright © 2014 Daniel Luchinger"

#property link

#property strict

#property strict

#property indicator_chart_window

#property indicator_buffers 4

#property indicator_color1 clrLime

#property indicator_color2 clrRed

#property indicator_color3 clrMagenta

#property indicator_color4 clrCyan

#define BUY 1

#define SELL 2

double Buy[],

Sell[],

FirstBuy[],

FirstSell[];

int OnInit() {

SetIndexBuffer(0,FirstBuy);

SetIndexBuffer(1,FirstSell);

SetIndexBuffer(2,Buy);

SetIndexBuffer(3,Sell);

for(int i=0; i<4; i++) {

SetIndexStyle (i,DRAW_ARROW,STYLE_SOLID,2);}

SetIndexArrow (0,233);

SetIndexArrow (1,234);

SetIndexArrow (2,233);

SetIndexArrow (3,234);

return(INIT_SUCCEEDED);}

void OnDeinit(const int reason) {}

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[]) {

static int lastSignal=0;

for(int i=MathMin(rates_total-prev_calculated, rates_total-1); i>=0; i--) {

FirstBuy=FirstSell=Buy=Sell=EMPTY_VALUE;

datetime when=Time;

if((High-Close)<0) {

if(lastSignal==SELL) {

FirstBuy=Close;

SoundAlert(when,"Buy");}

lastSignal=BUY;}

if((Low-Close)>0){

if(lastSignal==BUY) {

FirstSell=Close;

SoundAlert(when,"Sell");}

lastSignal=SELL;}

}

return(rates_total);}

void SoundAlert(datetime i, string dir) {

static datetime lastAlert=0;

if(lastAlert!=i) {

Alert(StringFormat("%s signal on %s at %s",dir,Symbol(),TimeToStr(i)));

daniel1983

Try it like this :

#property copyright "Copyright © 2014 Daniel Luchinger"

#property link ""

#property strict

#property strict

#property indicator_chart_window

#property indicator_buffers 4

#property indicator_color1 clrLime

#property indicator_color2 clrRed

#property indicator_color3 clrMagenta

#property indicator_color4 clrCyan

#define BUY 1

#define SELL 2

double Buy[],

Sell[],

FirstBuy[],

FirstSell[];

int OnInit() {

SetIndexBuffer(0,FirstBuy);

SetIndexBuffer(1,FirstSell);

SetIndexBuffer(2,Buy);

SetIndexBuffer(3,Sell);

for(int i=0; i<4; i++) {

SetIndexStyle (i,DRAW_ARROW,STYLE_SOLID,2);}

SetIndexArrow (0,233);

SetIndexArrow (1,234);

SetIndexArrow (2,233);

SetIndexArrow (3,234);

return(INIT_SUCCEEDED);}

void OnDeinit(const int reason) {}

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[]) {

static int lastSignal=0;

for(int i=MathMin(rates_total-prev_calculated, rates_total-2); i>=0; i--)

{

FirstBuy=FirstSell=Buy=Sell=EMPTY_VALUE;

datetime when=Time;

if((High-Close)<0) {

if(lastSignal==SELL) {

FirstBuy=Close;

SoundAlert(when,"Buy");}

lastSignal=BUY;}

if((Low-Close)>0){

if(lastSignal==BUY) {

FirstSell=Close;

SoundAlert(when,"Sell");}

lastSignal=SELL;}

}

return(rates_total);

}

void SoundAlert(datetime i, string dir) {

static datetime lastAlert=0;

if(lastAlert!=i) {

Alert(StringFormat("%s signal on %s at %s",dir,Symbol(),TimeToStr(i)));

}

}

 

Hi Mladen, thank you but writing the code this way, there are missing signals, please have a look i made a picture comparing them on daily chart USDJPY:

What can this be?

Files:
 
daniel1983:
Hi Mladen, thank you but writing the code this way, there are missing signals, please have a look i made a picture comparing them on daily chart USDJPY:

What can this be?

daniel1983

In your code you used future values (these :

High-Close

Low-Close

I used Close - which is a normal previous value. Change it to but then it will repaint

 

Dear mrtools and mladen

Can anybody assist? Tom Demark Moving Average is a key indicator within my strategy, however, an alarm would be very useful for when a new shelf is indicated; I would be very grateful if an alarm could coded into the indicator. Looking forward to your kind assistance.

Many thanks