//+------------------------------------------------------------------+//| Order Enter Function | //<< When this was getting called it was conducting all the mathematical formula's irrespective of the pending order!//+------------------------------------------------------------------+void OrderEntry(int direction)
{
//Padding for the stop and padding for the entry too. double ATR_Pad = iATR(NULL,60,14,1)/2;
double Buy_Pad = NormalizeDouble(ATR_Pad,Digits);
double Sell_Pad = NormalizeDouble(ATR_Pad,Digits);
//Get Highest Price in our lookback range and set buy price above it.int iTBT = iBarShift(NULL,60, triggerBarTime, true),
iHH = iHighest(NULL,60, MODE_HIGH, iTBT + CandlesBeforeBiasObtained, 0);
double Buy_Here = High[iHH] + Buy_Pad;
double buyPrice= NormalizeDouble(Buy_Here,Digits);
//Get Lowest Price in our lookback range and set sell price below it.int iTBT_1 = iBarShift(NULL, 60, triggerBarTime, true),
iLL = iLowest(NULL, 60, MODE_LOW, iTBT_1 + CandlesBeforeBiasObtained, 0);
double Sell_Here=Low[iLL] - Sell_Pad;
double sellPrice= NormalizeDouble(Sell_Here,Digits);
//Stop calculations. double ATR = iATR(NULL,60,14,1);
double MA = iMA(NULL,60,MA_Period,0,1,0,1);
double BuyStopPriceMath = MA - ATR;
double SellStopPriceMath = MA + ATR;
double BuyStopPrice = NormalizeDouble(BuyStopPriceMath,Digits);
double SellStopPrice = NormalizeDouble(SellStopPriceMath,Digits);
//get our buystop price from below the ma and our takeprofit based on our r:r ratio.double pips_to_bsl=buyPrice-BuyStopPrice;
double buy_tp_price=(pips_to_bsl*RewardRatio)+buyPrice;
double buy_takeprofit_price= NormalizeDouble(buy_tp_price, Digits);
//get our sellstop price from below the ma and our takeprofit based on our r:r ratio.double pips_to_ssl=SellStopPrice-sellPrice;
double sell_tp_price=sellPrice-(pips_to_ssl*RewardRatio);
double sell_takeprofit_price= NormalizeDouble(sell_tp_price, Digits);
//Lot calculation - Facilitates Notional and Lots within MT4 - As well as find the tick value relative to the account denomination. double risk_amount = AccountEquity( )*RiskPercent/100;
double Lot_Step = MarketInfo(Symbol(), MODE_LOTSTEP);
double ts = MarketInfo(Symbol(), MODE_TICKSIZE);
double tv = MarketInfo(Symbol(), MODE_TICKVALUE);
double minlot = MarketInfo(Symbol(), MODE_MINLOT);
double loss_for_1_lot = pips_to_bsl/ ts * tv ;
//Alert(loss_for_1_lot);double LotSize_Buy = MathFloor( risk_amount / loss_for_1_lot/ Lot_Step) * Lot_Step ;
//Alert(LotSize_Buy);double loss_for_1_lot1 = pips_to_ssl/ ts * tv ; //<<<<<<<<<<<<<<<<<<<< THIS WAS RUNNING THE EQUATION EVEN THOUGH IT WAS NOT REQUIRED!
//Alert(loss_for_1_lot1); //<<<<<<<<<<<<<<<<<<< THIS IS NOW MOVED TO WITHIN THE PARENTHESIS "DIRECTION == 1". double LotSize_Sell = MathFloor( risk_amount / loss_for_1_lot1/ Lot_Step) * Lot_Step ;
//Alert(LotSize_Sell);//+-------------------------------------------------------------------------------------+//| Order Buy Function |//+-------------------------------------------------------------------------------------+ //Place a pending buystop if no orders exists. Pending or otherwise.if(direction==0)
{
...
} // end of if(direction==0)///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //+---------------------------------------------------------------------------------------+//|Order Sell Function |//+---------------------------------------------------------------------------------------+ if(direction==1)
{//--Sell--//
...
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
是的,我正在看,因为你强调了这一点,谢谢!我将具体分解(我知道有人告诉我这样做!)整个公式,并跟踪它的错误所在。目前我无法理解为什么pips_to_ssl打印为 "0",而这甚至没有用于回测部分的挂单,它在那里打印了这个零除数...。
不是pips_to_bsl给了我 "0"...Strange....
好吧,我想我已经解决了这个问题--我只想感谢大家在提示方面对我的帮助!真的很感谢 :D!!!
基本上这就是它似乎出错的地方--注释在下面--我现在已经把对应于BUYSTOPS和SELLSTOPS的相关编码移到了它们应该在的地方!