How to code? - page 313

 

Hi,

it is possible with code modify only buy or sell order of the current active chart symbol?

It will be very usefull for me in a script where i use function WindowsPriceonDropped to open order.

Thank you

 

...

dasio,

Try something like this :

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

{

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

if (OrderSymbol()!=Symbol()) continue;

if (OrderType()==OP_BUY || OrderType()==OP_SELL)

{

// do the proccessing you wish here

}

}

dasio:
Hi,

it is possible with code modify only buy or sell order of the current active chart symbol?

It will be very usefull for me in a script where i use function WindowsPriceonDropped to open order.

Thank you
 

Who wants a challenge?

I need some code to do the following, see attached screenshot. This would be Buy trade.

I have tried a for loop, a mess of if conditions and neither has produced results that I'm looking for.

It appears to be simple but I have not been able to get it working.

Files:
maexample.jpg  54 kb
 

Your enter condition could be written similar to this :

double pipMultiplier = 1;

if (Digits==3 || Digits==5) pipMultiplier = 10;

double ma = iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,1);

bool openBuy = (Low[1]>ma && High[1]<(ma+5.0*Point*pipMultiplier));

if (openBuy)

{

// your code here

}

cyber1:
I need some code to do the following, see attached screenshot. This would be Buy trade.

I have tried a for loop, a mess of if conditions and neither has produced results that I'm looking for.

It appears to be simple but I have not been able to get it working.
 
mladen:
Your enter condition could be written similar to this :
double pipMultiplier = 1;

if (Digits==3 || Digits==5) pipMultiplier = 10;

double ma = iMA(NULL,0,20,0,MODE_SMA,PRICE_CLOSE,1);

bool openBuy = (Low[1]>ma && High[1]<(ma+5.0*Point*pipMultiplier));

if (openBuy)

{

// your code here

}

But theres much more to it than that.The code you posted would give me the signal for the bar that straddles the Moving Average. But I also need a way of entering a trade on any bar past the straddle bar up to 5 bars provided they do not exceed MA+5. The reason I'm not taking a buy signal on the straddle bar is there's another indicator that must show a TRUE value which may not be TRUE on the straddle bar but if it's TRUE at any bar up to 5 bars past straddle bar and has not exceeded the MA +5 limit I can still take a trade. Not taking multiple trades just one per set up.

The following is what I have so far. At this point I'm only marking eligible bars with an arrow underneath, buys only. Once I get that worked out then I will put in my code to execute the order. I know it looks simple but unless I'm missing something obvious it isn't.

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

double Poin;

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

//| Custom initialization function |

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

int init()

{

//---- indicators

if (Point==0.00001) Poin=0.0001;

else {

if (Point==0.001) Poin=0.01;

else Poin=Point;

}

//----

return(0);

}

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

// +

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

int deinit(){

return(0);

}

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

//| Custom indicator iteration function |

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

int start(){

int MAM1StartBar=1;

int M1MAEntryPoint1=0;

int M1MAEntryPoint2=5;

string sObjName;

//------Indicators-------------//

double MAM0= iMA(NULL,0,20,0,0,0,MAM1StartBar);

double MAM1= iMA(NULL,0,20,0,0,0,MAM1StartBar+1);

double M1High0 = NormalizeDouble(iHigh(NULL,PERIOD_M1,MAM1StartBar),Digits);

double M1High1 = NormalizeDouble(iHigh(NULL,PERIOD_M1,MAM1StartBar+1),Digits);

double M1High2 = NormalizeDouble(iHigh(NULL,PERIOD_M1,MAM1StartBar+2),Digits);

double M1High3 = NormalizeDouble(iHigh(NULL,PERIOD_M1,MAM1StartBar+3),Digits);

double M1High4 = NormalizeDouble(iHigh(NULL,PERIOD_M1,MAM1StartBar+4),Digits);

double M1High5 = NormalizeDouble(iHigh(NULL,PERIOD_M1,MAM1StartBar+5),Digits);

double M1Low0 = NormalizeDouble(iLow(NULL,PERIOD_M1,MAM1StartBar),Digits);

double M1Low1 = NormalizeDouble(iLow(NULL,PERIOD_M1,MAM1StartBar+1),Digits);

double M1Low2 = NormalizeDouble(iLow(NULL,PERIOD_M1,MAM1StartBar+2),Digits);

double M1Low3 = NormalizeDouble(iLow(NULL,PERIOD_M1,MAM1StartBar+3),Digits);

double M1Low4 = NormalizeDouble(iLow(NULL,PERIOD_M1,MAM1StartBar+4),Digits);

double M1Low5 = NormalizeDouble(iLow(NULL,PERIOD_M1,MAM1StartBar+5),Digits);

// double MAM1TRL1=NormalizeDouble(MAM0+M1MAEntryPoint1*Poin,Digits);

// double MAM1TRL2=NormalizeDouble(MAM0+M1MAEntryPoint2*Poin,Digits);

//Blue arrow indicates straddle bar

if(M1High0>= MAM0 && M1Low0<=MAM0){

sObjName="Test_BLine1"+Time[MAM1StartBar];

ObjectCreate(sObjName, OBJ_ARROW, 0, Time[MAM1StartBar],Low[MAM1StartBar]-1.5*Poin);

ObjectSet(sObjName, OBJPROP_ARROWCODE, 241);

ObjectSet(sObjName, OBJPROP_COLOR, Blue);

}

//Aqua arrow indicates straddle bar+1

if(M1Low1=MAM0){

if(M1High1<=MAM0+M1MAEntryPoint2*Poin){

if(M1Low0 > MAM0){

sObjName="Test_BLine2"+Time[MAM1StartBar];

ObjectCreate(sObjName, OBJ_ARROW, 0, Time[MAM1StartBar],Low[MAM1StartBar]-1*Poin);

ObjectSet(sObjName, OBJPROP_ARROWCODE, 241);

ObjectSet(sObjName, OBJPROP_COLOR, Aqua);

}

}

}

//----

return(0);

}

 

In this screenshot you would need to abort at bar 4 because bar 3 exceeds the MA +5 limit, which means at bar 4 you would need to check to see if bar 3 exceeded the MA +5 limit, it did so thats the end of this trade setup.

Here all 5 bars are eligible because none of them exceeded the MA +5 limit

Files:
 

In this screenshot you would need to abort at bar 4 because bar 3 exceeds the MA +5 limit, which means at bar 4 you would need to check to see if bar 3 exceeded the MA +5 limit, it did thats the end of this trade setup.

Here all 5 bars are eligible because none of them exceeded the MA +5 limit

 

...

cyber1

In your examples, as far as I see, in order to be able to abort as you describe, you also have to know the future (since before the "abort" bar the rules applied and would return a go signal)

On the other hand, if you try to test all the bars back for the condition to enter, eventually you will always have a "break of rule" and will not be able to enter the position

cyber1:
In this screenshot you would need to abort at bar 4 because bar 3 exceeds the MA +5 limit, which means at bar 4 you would need to check to see if bar 3 exceeded the MA +5 limit, it did thats the end of this trade setup.

Here all 5 bars are eligible because none of them exceeded the MA +5 limit

 

Close all Open trade EA

Can anyone help me to make this ea?

This EA will close ever open trade pair when reach target profit and loss.

When it close all, then start monitor the opened trade.

I have a limit talent to do this.

This ea separate from the main ea from each pairs.

 

Signal and resistance/support dinamyc lines.

May you help me to translate this indicator in MT4 Language?

a:=(hhv(close,tpr)+llv(close,tpr)+close)/3;

b:=(a1*2)-hhv(close,tpr);

moving b:=mov(b,tpr,simple);

c:=(a1*2)-llv(close,tpr);

moving c:=mov(c,tpr,simple);

d:=(hhv(close,tpr/2)+llv(close,tpr/2)+close)/3;

moving d:=mov(d,tpr/2,simple);

stream:=(b+c+d)/3;

moving stream:=mov(stream,tpr,simple).

hhv= max period value (the highest value of close price in the time period chosen)

llv= min period value (the lowest value of close price in the time period chosen)

tpr=time period (from 1 to whatever you want)

mov= moving average.

The output must have "stream" and "moving stream"! Even if it has also "b", "moving b", "c", "moving c", "d" and "moving d" it's not a bad thing!

Thanks.

This forum is great......

Lucmat

Files:
immagine.jpg  258 kb
Reason: