Exemplo n.º 1
0
        protected override void OnStart()
        {
            if (vDirection == TradeType.Buy)
            {
                vLabel = "BOTS_Buy_" + Symbol.Code;
            }
            else
            {
                vLabel = "BOTS_Sell_" + Symbol.Code;
            }

            if (Symbol.Code.Contains("JPY"))
            {
                vDivisor = 100;
            }

            // Instantiate Indicators
            i_atr = Indicators.AverageTrueRange(MarketSeries, 14, MovingAverageType.Exponential);
            i_ha  = Indicators.GetIndicator <HeikenAshiDirectionExitIndicator>(TimeFrame);

            Positions.Opened += PositionsOnOpened;
            Positions.Closed += PositionsOnClosed;

            CalculateTradeParameters();

            // check if a position is already open
            var posList = Positions.FindAll(vLabel);

            if (posList.Length == 0)
            {
                var vResult = ExecuteMarketOrder(vDirection, Symbol, vVolume, vLabel);
                if (vResult.IsSuccessful)
                {
                    vPos    = vResult.Position;
                    vResult = vPos.ModifyStopLossPips(vInitialSLPips);
                    if (vResult.IsSuccessful)
                    {
                        Print(vLabel + " INITIAL POSITION OPENED SUCCESSFULLY");
                    }
                    else
                    {
                        Print(vLabel + " INITIAL POSITION OPENED - PROBLEM MODIFYING STOP LOSS - " + vResult.ToString());
                    }
                }
                else
                {
                    Print(vLabel + " FAILED TO OPEN INITIAL POSITION - " + vResult.ToString());
                    Stop();
                }
            }
            else
            {
                vPos = posList[0];

                if (vDirection == TradeType.Buy && vPos.StopLoss > vPos.EntryPrice || vDirection == TradeType.Sell && vPos.StopLoss < vPos.EntryPrice)
                {
                    vAlreadyScaledOut = true;
                }
                // hasn't scaled out yet
                else
                {
                    vScaleOutTPPrice = Convert.ToDouble(vPos.TakeProfit);
                    double?d       = null;
                    var    vResult = vPos.ModifyTakeProfitPrice(d);

                    if (vResult.IsSuccessful)
                    {
                        Print(vLabel + " RESTARTED SUCCESSFULLY - EXISTING POSITION IDENTIFIED");
                    }
                    else
                    {
                        Print(vLabel + " PROBLEM RESTARTING POSITION - " + vResult.ToString());
                    }
                }
            }



            if (vDirection == TradeType.Buy)
            {
                vScaleOutTPPrice    = vPos.EntryPrice + (vScaleOutTPPips / vDivisor);
                vStartTrailingPrice = vPos.EntryPrice + (vStartTrailingPips / vDivisor);
            }
            else
            {
                vScaleOutTPPrice    = vPos.EntryPrice - (vScaleOutTPPips / vDivisor);
                vStartTrailingPrice = vPos.EntryPrice - (vStartTrailingPips / vDivisor);
            }

            if (vDirection == TradeType.Buy && vStartTrailingPrice < vScaleOutTPPrice || vDirection == TradeType.Sell && vStartTrailingPrice > vScaleOutTPPrice)
            {
                vStartTrailingPrice = vScaleOutTPPrice;
            }

            Chart.DrawStaticText("cScaleOutSLPrice", ("\n\n\n\n\n\n Scale Out TP price " + vScaleOutTPPrice), VerticalAlignment.Top, HorizontalAlignment.Left, "Yellow");
        }
Exemplo n.º 2
0
        protected override void OnStart()
        {
            if (vDirection == TradeType.Buy)
            {
                vLabel = "BOTS_BUY_PIPS_" + Symbol.Code;
            }
            else
            {
                vLabel = "BOTS_SELL_PIPS_" + Symbol.Code;
            }

            if (Symbol.Code.Contains("JPY"))
            {
                vDivisor = 100;
            }

            // Instantiate Indicators
            if (pUseExitIndicator)
            {
                i_ha = Indicators.GetIndicator <HeikenAshiDirectionExitIndicator>(TimeFrame);
            }

            Positions.Opened += PositionsOnOpened;
            Positions.Closed += PositionsOnClosed;

            CalculateTradeParameters();

            // check if a position is already open
            var posList = Positions.FindAll(vLabel);

            if (posList.Length == 0)
            {
                var vResult = ExecuteMarketOrder(vDirection, Symbol, vVolume, vLabel);
                if (vResult.IsSuccessful)
                {
                    vPos    = vResult.Position;
                    vResult = vPos.ModifyStopLossPips(pInitialSLPips);
                    if (vResult.IsSuccessful)
                    {
                        Print(vLabel + " INITIAL POSITION OPENED SUCCESSFULLY");
                    }
                    else
                    {
                        Print(vLabel + " INITIAL POSITION OPENED - PROBLEM MODIFYING STOP LOSS - " + vResult.ToString());
                    }
                }
                else
                {
                    Print(vLabel + " FAILED TO OPEN INITIAL POSITION - " + vResult.ToString());
                    Stop();
                }
            }
            else
            {
                vPos = posList[0];

                if (vDirection == TradeType.Buy && vPos.StopLoss > vPos.EntryPrice || vDirection == TradeType.Sell && vPos.StopLoss < vPos.EntryPrice)
                {
                    vAlreadyScaledOut = true;
                }
                // hasn't scaled out yet
                else
                {
                    vScaleOutTPPrice = Convert.ToDouble(vPos.TakeProfit);
                    double?d       = null;
                    var    vResult = vPos.ModifyTakeProfitPrice(d);

                    if (vResult.IsSuccessful)
                    {
                        Print(vLabel + " RESTARTED SUCCESSFULLY - EXISTING POSITION IDENTIFIED");
                    }
                    else
                    {
                        Print(vLabel + " PROBLEM RESTARTING POSITION - " + vResult.ToString());
                    }
                }
            }

            if (vDirection == TradeType.Buy)
            {
                vScaleOutTPPrice    = vPos.EntryPrice + (pScaleOutPips / vDivisor);
                vStartTrailingPrice = vPos.EntryPrice + (pTrailingPips / vDivisor);
            }
            else
            {
                vScaleOutTPPrice    = vPos.EntryPrice - (pScaleOutPips / vDivisor);
                vStartTrailingPrice = vPos.EntryPrice - (pTrailingPips / vDivisor);
            }
        }