خلينا نبدأ كده بحاجه بسيطه و هانوصل بعد كده لحاجه اكثر تعقيدا
لازم نبص للموضوع من فوق شويه على افتراض اننا عارفين الاساسيات زى Variables and if conditions
عادة ال actions اللى الاكسبرت بيعملها بتكون حاجه من اتنين
1- حاجات بيعملها مع كل tick زى اننا نشوف الربح عشان نقفل او نعدل صفقه
2- حاجات تانيه بنعملها مع افتتاح كل شمعه زى اننا نشوف تقاطع المتوسطات عشان نقرر ندخل الصفقه او لأ
ده مثال من الكود
كود:
int OnInit()
{
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//--- destroy timer
Print("LOWEST MARGIN LEVEL :: ",NormalizeDouble(lowest_margin_level*100,1),"%");
Print("LOWEST EQUITY LEVEL :: ",NormalizeDouble(lowest_equity_percent*100,1),"%");
EventKillTimer();
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(AccountMargin() != 0)
{
if( (AccountEquity()/AccountMargin()) < lowest_margin_level) lowest_margin_level = (AccountEquity()/AccountMargin());
}
if( (AccountEquity()/AccountBalance()) < lowest_equity_percent) lowest_equity_percent = (AccountEquity()/AccountBalance());
buy_cnt=0;sell_cnt=0;BL_cnt=0;SL_cnt=0;BS_cnt=0;SS_cnt=0;
for(int i=OrdersTotal()-1 ; i>=0; i--)
{
if(OrderSelect(i,SELECT_BY_POS)==true && OrderSymbol()==Symbol())
{
if (OrderType()==OP_BUY) buy_cnt++;
else if(OrderType()==OP_SELL) sell_cnt++;
else if(OrderType()==OP_BUYLIMIT) BL_cnt++;
else if (OrderType()==OP_SELLLIMIT) SL_cnt++;
else if (OrderType()==OP_BUYSTOP) BS_cnt++;
else if (OrderType()==OP_SELLSTOP) SS_cnt++;
}
}
if(iBars(NULL,EntryFrame) > PreviousBars)
{
StateMachine();
PreviousBars = iBars(NULL,EntryFrame);
}
}