مطلوب مساعدة في هذا الكود
السلام عليكم ..
احاول برمجة شي بسيطة هو ... تنبيه على اختراق متوسط ما .. ولكن لا يعمل الكود بالشكل المطلوب ..
فارجو المراجعة و التصحيح ... :icon26:
كود:
//+------------------------------------------------------------------+
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright " "
#property link "http://www.metaquotes.net"
#property indicator_chart_window
extern int Time_Frame = PERIOD_H1;
extern int MA_Period = 10;
extern int MA_Method = MODE_SMA;
extern int MA_applied_to = PRICE_CLOSE;
extern bool Enabled = true;
extern int WhatCorner=2;
int PrevAlertTime=0;
// MODE_SMA 0 Simple moving average.
// MODE_EMA 1 Exponential moving average.
// MODE_SMMA 2 Smoothed moving average.
// MODE_LWMA 3 Linear weighted moving average.
// PRICE_CLOSE 0 Close price.
// PRICE_OPEN 1 Open price.
// PRICE_HIGH 2 High price.
// PRICE_LOW 3 Low price.
// PRICE_MEDIAN 4 Median price, (high+low)/2.
// PRICE_TYPICAL 5 Typical price, (high+low+close)/3.
// PRICE_WEIGHTED 6 Weighted close price, (high+low+close+close)/4.
//---- buffers
//+------------------------------------------------------------------+
//| 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
if (iBars(NULL,0) < BarsCount)
BarsCount = iBars(NULL,0) ;
for (int i =BarsCount; i>=0; i--)
{
double m = iMA(NULL,Time_Frame,MA_Period,0,MA_Method,MA_applied_to,i);
if ((CurTime() - PrevAlertTime > 20) && Close[i] < m && m < Close[i-1])
{
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[i-1] < m && m < Close [i] )
{
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
}
//+------------
رد: مطلوب مساعدة في هذا الكود
كود:
// if close of i < iMA && iMA < close of i-1 && last time alart .. then sell
if (iBars(NULL,0) < BarsCount)
BarsCount = iBars(NULL,0) ;
for (int i =BarsCount; i>=0; i--)
{
double m = iMA(NULL,Time_Frame,MA_Period,0,MA_Method,MA_applied_to,i);
if ( Close[i] < m && m < Close[i-1])
{
Alert ("Sell " + Symbol());
}
// if close of i-1 < iMA && iMA < close of i && last time alart .. then buy
if (Close[i-1] < m && m < Close [i])
{
Alert ("Buy "+ Symbol());
}
المشكلة في هذا الجزء من الكود ..
وضعت الكود بشكل مبسط الان ..
لا اعلم لماذا لا يعمل هذا الكود بالشكل المطلوب .. :ohmy:
رد: مطلوب مساعدة في هذا الكود
ادعو الله العليم القدير ان يسخر العقول
النيرة و القلوب السخية لهذه الطلب
:icon26::eh_s(7):
1 مرفق
رد: مطلوب مساعدة في هذا الكود
و عليكم السلام و رحمة الله تعالى و بركاته
في المرفقات