How to code? - page 221

 

Please help me to move the line.

--------------------------------------------------------------------------------

The indicator works as it was design. Sound alarm when price touches the line but i want to expand on that. I want this:

Copy the indicator below then do this 2 modifications:

modification #1:

create a line stoploss1(is already there) and move the line to where ever my stop loss is if i do not have an stop loss set move the line 500 pips away to prevent the alarm from being activated.

modification #2:

Create a line takeprofit1(this is not in the code) and move the line to where ever my stop loss is if i do not have a stop loss set move the line 502 pips away to prevent the alarm from being activated. Also use different sound alert.

Pretty much the indicator will be checking what my stop loss and take profit is and will move at they respective prices if stop loss and take profit is not set will move the lines 500,502 pips away.

That way when the market hit my profit or stop loss the sound will let me know when im not looking at metatrader or have the window minimize, and i can go back i see what other set up i may have.

Thank you very much for your help brother.

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

//| HLine Alert.mq4 |

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

#property copyright ""

#property indicator_chart_window

extern string LineName="Stoploss1";

extern color LineColor=Red;

extern int LineStyle=STYLE_SOLID;

extern int AlertPipRange=1;

extern string AlertWav="Alert2.wav";

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

//| Custom indicator initialization function |

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

int init()

{

//---- indicators

//----

return(0);

}

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

//| Custom indicator deinitialization function |

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

int deinit()

{

//----

//----

return(0);

}

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

//| Custom indicator iteration function |

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

int start()

{

int counted_bars=IndicatorCounted();

ObjectCreate(LineName, OBJ_HLINE, 0, 0, Bid);

ObjectSet(LineName, OBJPROP_STYLE, LineStyle);

ObjectSet(LineName, OBJPROP_WIDTH, 2);

ObjectSet(LineName, OBJPROP_COLOR, LineColor);

double val = ObjectGet( LineName, OBJPROP_PRICE1);

if (Bid-AlertPipRange*Point = val) PlaySound(AlertWav);

//----

//----

return(0);

}

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

 
increase:
Here is an MTF version I did for you with alert

Hi Increase..

...I download your indicator (with alert) I did fix it..cause..have a little error..

once pop up arrow up show label down and viceversa...

so I would to know how to merge both in one..and how to set send alert to

e-mail in all TF's.

than u in advance

Files:
afstar.mq4  6 kb
 

please i need help

please can anyone help me with writing codes i want to develop a robot for a scalping strategy i discovered

 

Guys,

here is a simple code for alert on moving average crossing & closing as per attached picture,

I'm think there is something wrong with the if statement, please review,

thanks in advance.

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

#property copyright "Non"

#property link "non"

#property indicator_chart_window

extern int Time_Frame = PERIOD_M5;

extern int MA_Period = 20;

extern int MA_Method = MODE_SMA;

extern int MA_applied_to = PRICE_CLOSE;

extern bool Enabled = true;

extern int WhatCorner=2;

int PrevAlertTime=0;

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

//| Custom indicator initialization function |

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

int init()

{

//---- indicators

//----

return(0);

}

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

//| Custom indicator deinitialization function |

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

int deinit()

{

//----

ObjectDelete("Alart_Condition");

ObjectDelete("Alart_Setup");

//----

return(0);

}

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

//| Custom indicator iteration function |

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

int start()

{

int BarsCount=IndicatorCounted();

if (Enabled == false)

{

string Alart_Condition = "Alart Disabled";

ObjectCreate("Alart_Condition", OBJ_LABEL, 0, 0, 0);

ObjectSetText("Alart_Condition", Alart_Condition , 12, "Comic Sans MS", Red);

ObjectSet("Alart_Condition", OBJPROP_CORNER, WhatCorner);

ObjectSet("Alart_Condition", OBJPROP_XDISTANCE, 1);

ObjectSet("Alart_Condition", OBJPROP_YDISTANCE, 1);

return (0);

}

// if (!Enabled) return (0);

if (Enabled == true)

{

string Alart_Setup = (GetMethodText1(MA_Method)+ (DoubleToStr(MA_Period,0))+")"+ GetMethodText(MA_applied_to)) ;

ObjectCreate("Alart_Setup", OBJ_LABEL, 0, 0, 0);

ObjectSetText("Alart_Setup", Alart_Setup , 12, "Comic Sans MS", Red);

ObjectSet("Alart_Setup", OBJPROP_CORNER, WhatCorner);

ObjectSet("Alart_Setup", OBJPROP_XDISTANCE, 1);

ObjectSet("Alart_Setup", OBJPROP_YDISTANCE, 1);

}

// if close of i < iMA && iMA < close of i-1 && last time alart .. then sell

for (int i=Bars;i>=1;i--)

{

double m = iMA(NULL,Time_Frame,MA_Period,0,MA_Method,MA_applied_to,i);

if ((CurTime() - PrevAlertTime > 20) && Close < m && m < Close)

{

Alert ("Sell " + Symbol());

PlaySound ("alert.wav");

PrevAlertTime=CurTime();

return(-1);

}

// if close of i-1 < iMA && iMA < close of i && last time alart .. then buy

if ( (CurTime() - PrevAlertTime > 20) && Close < m && m < Close )

{

Alert ("Buy "+ Symbol());

PlaySound ("alert.wav");

PrevAlertTime=CurTime();

return(-1);

}

}

//----

//----

return(0);

}

string GetMethodText1(int MA_Method)

{ switch(MA_Method)

{

case 0 : return("SMA("); break;

case 1 : return("EMA("); break;

case 2 : return("SMMA("); break;

case 3 : return("LWMA("); break; }

}

string GetMethodText(int MA_applied_to)

{

switch(MA_applied_to)

{case 0: return("C"); break; // Close

case 1: return("O"); break; // Open

case 2: return("H"); break; // High

case 3: return("L"); break; } // Low

}

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

Files:
q.gif  10 kb
 

Help with script

Hi...

I'm complete newbie at coding this so i was wondering if anyone could tell what's wrong with this script...

I keep getting an errer 4109 ERR_TRADE_NOT_ALLOWED.. message in MT4 is "Invalid price 1.48770000 for OrderSend function" But I can't seem to figure out why... So please help me out here...

int start()

{

double High1;

double Low1;

double TP = 50;

double SL = 50;

int Lots = (((AccountBalance()/15)/50)/10);

//----

{

High1 = iHigh(NULL, PERIOD_D1, 0);

Low1 = iLow(NULL, PERIOD_D1, 0);

double Buy = High1*Point;

double Sell= Low1*Point;

Print(Buy);

Print(Sell);

}

//----

{

OrderSend(Symbol(),OP_BUYSTOP,Lots,Buy,NULL,Ask-SL*Point,Ask+TP*Point);

OrderSend(Symbol(),OP_SELLSTOP,Lots,Sell,3,Bid+SL*Point,Bid-TP*Point);

Alert (GetLastError());

}

//----

return(0);

}
 

Help

Atleast now i figured out my trade not allowed problem..

But now i keep getting an "invalid stops" error.. someone who can enlighten me here..? Don't really understand whats wrong here...

Thanks in advance..

int start()

{

double High1;

double Low1;

int TP = 50;

int SL = 50;

int Lots = (((AccountBalance()/15)/50)/10);

//----

{

High1 = iHigh(NULL, PERIOD_D1, 0);

Low1 = iLow(NULL, PERIOD_D1, 0);

Print(High1);

Print(Low1);

}

//----

{

OrderSend(Symbol(),OP_BUYSTOP,Lots,High1,NULL,Ask-SL*Point,Ask+TP*Point);

OrderSend(Symbol(),OP_SELLSTOP,Lots,Low1,NULL,Bid+SL*Point,Bid-TP*Point);

Alert (GetLastError());

}

//----

return(0);

}
 

Restrict the number for trades to....

I am trying to add code to an EA that will restrict the number of trades it makes per day to only two(2). Only ONE long trade and ONE short trade per day. This is the code I have so far, but on a back test it is not working.

Can you help me!?

datetime LongTrade=0;

datetime ShortTrade=0;

if(countOrders(OP_BUY,magic)==0 && LongTrade!=iTime(NULL,PERIOD_D1,0))

{

OrderSend(Symbol(),OP_BUY,lots,Ask,0,Bid-stop_loss*Point,lTP,comment + "lTP",magic);

LongTrade=iTime(NULL,PERIOD_D1,0);

return(0);

}

--------------------

if(countOrders(OP_SELL,magic)==0 && ShortTrade!=iTime(NULL,PERIOD_D1,0))

{

OrderSend(Symbol(),OP_SELL,lots,Bid,0,Ask+stop_loss*Point,sTP,comment + "sTP",magic);

ShortTrade=iTime(NULL,PERIOD_D1,0);

return(0);

}

THANK YOU.

 
ForExTyro:
I am trying to add code to an EA that will restrict the number of trades it makes per day to only two(2). Only ONE long trade and ONE short trade per day. This is the code I have so far, but on a back test it is not working. Can you help me!?

Replace

datetime LongTrade=0;

datetime ShortTrade=0;

to

static datetime LongTrade=0;

static datetime ShortTrade=0;

 

Help with this EA & Indicator Please

Im a Newbe so Hi, as you can see Im having no luck with this.

I have this Indicator (Histogram/ looks back 300 bars but it repaints WAY to much. Can anyone suggest an Indicator that does not yet will do the same job.This is it, if you can help that would be fantastic

Regards CharlieC

histoind.mq4

#property indicator_chart_window

#property indicator_buffers 2

#property indicator_color1 Red

#property indicator_color2 LawnGreen

string gs_unused_124 = "";

bool gi_unused_132 = FALSE;

extern int RISK = 3;

extern int CountBars = 300;

double g_ibuf_144[];

double g_ibuf_148[];

int init() {

IndicatorBuffers(2);

SetIndexStyle(0, DRAW_ARROW);

SetIndexArrow(0, 234);

SetIndexStyle(1, DRAW_ARROW);

SetIndexArrow(1, 233);

SetIndexBuffer(0, g_ibuf_144);

SetIndexBuffer(1, g_ibuf_148);

Comment();

return (0);

}

int start() {

int li_12;

double ld_52;

double ld_60;

double ld_68;

double ld_76;

double ld_84;

double ld_92;

double ld_100;

double lda_108[50000];

SetIndexDrawBegin(0, Bars - CountBars + 11 + 1);

SetIndexDrawBegin(1, Bars - CountBars + 11 + 1);

int l_ind_counted_8 = IndicatorCounted();

int li_20 = RISK * 2 + 3;

double ld_36 = RISK + 67;

double ld_44 = 33 - RISK;

int l_period_24 = li_20;

if (Bars <= 12) return (0);

if (l_ind_counted_8 < 12) {

for (int li_0 = 1; li_0 <= 0; li_0++) g_ibuf_144[CountBars - li_0] = 0.0;

for (li_0 = 1; li_0 <= 0; li_0++) g_ibuf_148[CountBars - li_0] = 0.0;

}

for (int li_4 = CountBars - 11 - 1; li_4 >= 0; li_4--) {

li_12 = li_4;

ld_76 = 0.0;

ld_84 = 0.0;

for (li_12 = li_4; li_12 <= li_4 + 9; li_12++) ld_84 += MathAbs(High[li_12] - Low[li_12]);

ld_76 = ld_84 / 10.0;

li_12 = li_4;

ld_68 = 0;

while (li_12 < li_4 + 9 && ld_68 < 1.0) {

if (MathAbs(Open[li_12] - (Close[li_12 + 1])) >= 2.0 * ld_76) ld_68 += 1.0;

li_12++;

}

if (ld_68 >= 1.0) ld_92 = li_12;

else ld_92 = -1;

li_12 = li_4;

ld_68 = 0;

while (li_12 < li_4 + 6 && ld_68 < 1.0) {

if (MathAbs(Close[li_12 + 3] - Close[li_12]) >= 4.6 * ld_76) ld_68 += 1.0;

li_12++;

}

if (ld_68 >= 1.0) ld_100 = li_12;

else ld_100 = -1;

if (ld_92 > -1.0) l_period_24 = 3;

else l_period_24 = li_20;

if (ld_100 > -1.0) l_period_24 = 4;

else l_period_24 = li_20;

ld_52 = 100 - MathAbs(iWPR(NULL, 0, l_period_24, li_4));

lda_108[li_4] = ld_52;

g_ibuf_144[li_4] = 0;

g_ibuf_148[li_4] = 0;

ld_60 = 0;

if (ld_52 < ld_44) {

for (int li_16 = 1; lda_108[li_4 + li_16] >= ld_44 && lda_108[li_4 + li_16] <= ld_36; li_16++) {

}

if (lda_108[li_4 + li_16] > ld_36) {

ld_60 = High[li_4] + ld_76 / 2.0;

g_ibuf_144[li_4] = ld_60;

}

}

if (ld_52 > ld_36) {

for (li_16 = 1; lda_108[li_4 + li_16] >= ld_44 && lda_108[li_4 + li_16] <= ld_36; li_16++) {

}

if (lda_108[li_4 + li_16] < ld_44) {

ld_60 = Low[li_4] - ld_76 / 2.0;

g_ibuf_148[li_4] = ld_60;

}

}

}

return (0);

}

Files:
histoind.mq4  3 kb
 

CharlieC

While I'm at it, can someome put a sound Alert on it as well (Darn Cheeky Ay, for a Newbeeee) this stuff makes ya do funny things

Sorry

CharlieC

Reason: