using System; using System.ComponentModel; using System.Windows.Media; using Alveo.Interfaces.UserCode; using Alveo.UserCode; using Alveo.Common; using Alveo.Common.Classes; namespace Alveo.UserCode { [Serializable] [Description("Anti-Martingale-OverNight-Setup as explained by Seve Perry")] public class AntiMartingaleOverNightSetup : ScriptBase { #region Properties [Category("Settings")] [Description("Default lot size to use if not already set in Alveo script variables")] public double DEFAULT_LOT_SIZE{ get; set;} [Category("Settings")] [Description("Default pips distance in pips from the current price")] public int DEFAULT_PIPS_DIST{ get; set;} [Category("Settings")] [Description("Default grid distance in pips - how far appart the trades should be")] public int DEFAULT_GRID_DIST{ get; set;} string currentSymbol; double stopLoss; double takeProfit; double lotSize; double bidPrice; double pipPos; double initialBuyOpenPrice; double initialSellOpenPrice; double buyProfitTarget; double sellProfitTarget; double buyStopLoss; double sellStopLoss; double gridDist; int numTrades; int ticket; #endregion public AntiMartingaleOverNightSetup () { // Basic script initialization. Don't use this constructor to calculate values copyright = "Steve Perry - Writen by Pawel Michalowski"; link = ""; DEFAULT_LOT_SIZE = 0.01; DEFAULT_PIPS_DIST = 20; DEFAULT_GRID_DIST = 2; } //+------------------------------------------------------------------+" //| script program start function |" //+------------------------------------------------------------------+" protected override int Start() { // ENTER YOUR CODE HERE currentSymbol = Symbol(); MessageBox("Anti Martingale Overnight Trading Strategy script for " + currentSymbol + " now starting up."); // Get global variables for stop loss, take profit, and lot size stopLoss = GlobalVariableGet("default_stoploss"); takeProfit = GlobalVariableGet("default_takeprofit"); if (GlobalVariableCheck("default_quantity")) { // Set the default lot size to the global variable lotSize = GlobalVariableGet("default_quantity"); } else { // Set lot size to constant field at beginning of class lotSize = DEFAULT_LOT_SIZE; } // Is Yen pair? pipPos = currentSymbol.EndsWith("JPY") ? 100 : 10000; // We want trades in increments of 2 pips all the way to the profit target numTrades = (int)(takeProfit / 2.0); // Here we get the current bid price and add designated number of pips for the initial trade entries bidPrice = MarketInfo(currentSymbol, MODE_BID); // Initial buy price initialBuyOpenPrice = bidPrice + (DEFAULT_PIPS_DIST / pipPos); // Buy profit target and stop loss buyProfitTarget = initialBuyOpenPrice + (takeProfit / pipPos); buyStopLoss = initialBuyOpenPrice - (stopLoss / pipPos); // Distance between successive trades in pips gridDist = DEFAULT_GRID_DIST / pipPos; // Add buy entries //for (int i = 0; i <= numTrades; i++) //{ // ticket = OrderSend(currentSymbol, OP_BUYSTOP, lotSize, initialBuyOpenPrice + (i * gridDist), 0, buyStopLoss + (i * gridDist), buyProfitTarget); // Sleep(3000); //} // Initial sell price initialSellOpenPrice = bidPrice - (DEFAULT_PIPS_DIST / pipPos); // Sell profit target and stop loss sellProfitTarget = initialSellOpenPrice - (takeProfit / pipPos); sellStopLoss = initialSellOpenPrice + (stopLoss / pipPos); // Add sell entries for (int i = 0; i <= numTrades; i++) { ticket = OrderSend(currentSymbol, OP_SELLSTOP, lotSize, initialSellOpenPrice - (i * gridDist), 0, sellStopLoss - (i * gridDist), sellProfitTarget); Sleep(3000); } MessageBox("Anti Martingale Overnight Trading Strategy script for " + currentSymbol + " finished."); return 0; } } }