标题: 小白求助,谁帮我改个非常简单的小功能 [打印本页] 作者: houhou555 时间: 2017-1-4 20:20 标题: 小白求助,谁帮我改个非常简单的小功能 就是开多单变成开空单,相反,原本要开空单的变成开多单,然后移动止损可以用
我自己改的移动止损用不了。。。
[C++] 纯文本查看 复制代码// -------------------------------------------------------------------------------------------------
#property show_inputs
#include
//----------------------- Externals ----------------------------------------------------------------
// All externals here have their name starting with a CAPITAL character
extern string Configuration = "==== Configuration ====";
extern int Magic = 0; // If set to a number less than 0 it will calculate MagicNumber automatically
extern string OrderCmt = ""; // Trade comments that appears in the Trade and Account History tab
extern bool NDDmode = FALSE; // For brokers that don't accept SL and TP to be sent at the same time as the order
extern bool Show_Debug = FALSE; // Print huge log files with info, only for debugging purposes
extern bool Verbose = FALSE; // Additional information printed in the chart
extern string TradingSettings = "==== Trade settings ====";
extern bool TradeALLCurrencyPairs = FALSE; // If set to TRUE it weill trade on all pairs automatically, otherwise only on the chart pair
extern double MaxSpread = 20.0; // Max allowed spread in points (1 / 10 pip)
extern int MaxExecution = 0; // Max allowed average execution time in ms (0 means no restrictions)
extern double TakeProfit = 25.0; // TakeProfit from as many points. Default 10 (= 1 pip)
extern double StopLoss = 25.0; // StopLoss from as many points. Default 60 (= 6 pips)
extern double TrailingStart = 0; // Start trailing profit from as so many pips. Default 0
extern double Commission = 0; // Some broker accounts charge commission in USD per 1.0 lot. Commission in points
extern bool UseDynamicVolatilityLimit = TRUE;// Calculate VolatilityLimit based on INT (spread * VolatilityMultiplier)
extern double VolatilityMultiplier = 125; // Only used if UseDynamicVolatilityLimit is set to TRUE
extern double VolatilityLimit = 180; // Only used if UseDynamicVolatilityLimit is set to FALSE
extern bool UseVolatilityPercentage = TRUE; // If true, then price must break out more than a specific percentage
extern double VolatilityPercentageLimit = 60;// Percentage of how much iHigh-iLow difference must differ from VolatilityLimit
extern bool UseMovingAverage = TRUE; // User two iMA as channel
extern bool UseBollingerBands = TRUE; // Use iBands as channel
extern double Deviation = 1.50; // Deviation for iBands
extern int OrderExpireSeconds = 3600; // Orders are deleted after so many seconds
extern string Money_Management = "==== Money Management ====";
extern bool MoneyManagement = TRUE; // If TRUE then calculate lotsize automaticallay based on Risk, if False then use ManualLotsize below
extern double MinLots = 0.01; // Minimum lot-size to trade with
extern double MaxLots = 0.05; // Maximum allowed lot-size to trade with
extern double Risk = 1.0; // Risk setting in percentage, For 10.000 in Balance 10% Risk and 60 StopLoss lotsize = 16.66
extern double ManualLotsize = 0.1; // Manual lotsize to trade with if MoneyManagement above is set to FALSE
extern string Screen_Shooter = "==== Screen Shooter ====";
extern bool TakeShots = FALSE; // Save screen shots on STOP orders?
extern int DelayTicks = 1; // Delay so many ticks after new bar
extern int ShotsPerBar = 1; // How many screen shots per bar
//--------------------------- Globals --------------------------------------------------------------
// All globals have their name written in lower case characters
string suffix;
string allpairs[26] = {"EURUSD","USDJPY","GBPUSD","USDCHF","USDCAD","AUDUSD","NZDUSD","EURJPY","GBPJPY","CHFJPY","CADJPY","AUDJPY","NZDJPY","EURCHF","EURGBP","EURCAD","EURAUD","EURNZD","GBPCHF","GBPAUD","GBPCAD","GBPNZD","AUDCHF","AUDCAD","AUDNZD","NZDCHF","NZDCAD","CADCHF"}; // Currency pairs to be watched
string brokerpairs[]; // Of the above 27 possible pairs, store all pairs that the broker support for trading here
bool openorders = FALSE;
bool global_picwasshot = FALSE;
int indicatorperiod = 3; // period for indicators
int distance = 0;
int brokerdigits = 0;
int slippage = 3;
int globalerror = 0;
int lasttime = 0;
int tickcounter = 0;
int upto30counter = 0;
int paircount = 26; // For trade on all pairs - number of currency pairs 27 (0 - 26)
int execution = -1;
int avg_execution = 0;
int execution_samples = 0;
int starttime;
double maxamount = 0.0;
double lotsize = 0.1;
double array_spread[30];
double highest;
double lowest;
double lotstep;
//======================= Program initialization ===================================================
int init()
{
string local_textstring;
string local_riskstring;
int stoplevel;
double local_risk;
// Adjust SL, TP and distance to broker stoplevel if they are less than this stoplevel
stoplevel = MathMax(MarketInfo(Symbol(), MODE_FREEZELEVEL), MarketInfo(Symbol(), MODE_STOPLEVEL));
if (StopLoss MarketInfo(Symbol(), MODE_MAXLOT))
MaxLots = MarketInfo(Symbol(), MODE_MAXLOT);
if (MaxLots 100.0)
Risk = 100;
// Also make sure that if the risk-lpercentage is too low, that it's adjusted to lowest possible lotsize
local_risk = sub_recalculatewrongrisk(Symbol(), MinLots);
if (Risk = local_imalow + local_imadiff / 2.0;
// Calculate a channel on BollingerBands, and check if the prcice is outside of this channel
local_ibandsupper = iBands(local_pair, PERIOD_M1, indicatorperiod, Deviation, 0, PRICE_OPEN, MODE_UPPER, 0);
local_ibandslower = iBands(local_pair, PERIOD_M1, indicatorperiod, Deviation, 0, PRICE_OPEN, MODE_LOWER, 0);
local_ibandsdiff = local_ibandsupper - local_ibandslower;
local_isbidgreaterthanibands = local_bid >= local_ibandslower + local_ibandsdiff / 2.0;
// Calculate average true spread, which is the average of the spread for the last 30 tics
ArrayCopy(array_spread, array_spread, 0, 1, 29);
array_spread[29] = local_spread;
if (upto30counter VolatilityLimit)
{
// Calculate how much it differs
local_volatilitypercentage = local_volatility / VolatilityLimit;
// In case of UseVolatilityPercentage == TRUE then also check if it differ enough of percentage
if ((UseVolatilityPercentage == FALSE) || (UseVolatilityPercentage == TRUE && local_volatilitypercentage > VolatilityPercentageLimit))
{
if (local_bid highest)
local_pricedirection = 1; // SELL or SELLSTOP
}
}
else
local_volatilitypercentage = 0;
}