单量风险控制
#property copyright "shiyingpan"#property link "https://aijy.github.io"
#property version "1.00"
#property strict
input double 万美金最大单量=2; //--- 一万美金可下几首单量,按比例缩减
bool new_orders=true;
double max_lots=0;
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
int OnInit()
{
while(AccountNumber()==0)
Sleep(10000);
max_lots=AccountEquity()/10000*万美金最大单量;
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
}
//+------------------------------------------------------------------+
//| |
//+------------------------------------------------------------------+
void OnTick()
{
double total_lots=0;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
total_lots=total_lots+OrderLots();
}
}
if(total_lots>max_lots)
{
new_orders=false;
}
if(new_orders==true)
{
Print("当前单量未超最大单量,允许下单");
}
}
页:
[1]