- www.mql5.com
hi GiLR,
my suggestion
int OnCalculate(....)
{
MqlDateTime urustime;
TimeCurrent(urustime);
if(urustime.mon<=12 && urustime.year<=2012) return;
.............
}
- www.mql5.com
hi GiLR,
my suggestion
int OnCalculate(....)
{
MqlDateTime urustime;
TimeCurrent(urustime);
if(urustime.mon<=12 && urustime.year<=2012) return;
.............
}
Thank you- Indicator would expire last day in Dec 2012 - Correct?
In this is the code below, where would I add the above code? I know nothing about coding
Thanks
//+------------------------------------------------------------------+ // SchaffTrendCycle.mq5 | //| Copyright ?2011, EarnForex.com | //| http://www.earnforex.com/ | //+------------------------------------------------------------------+ #property copyright "Copyright ?2011, EarnForex.com" #property link "http://www.earnforex.com" #property version "1.0" #property description "Schaff Trend Cycle - Cyclical Stoch over Stoch over MACD." #property description "Falling below 75 is a sell signal." #property description "Rising above 25 is a buy signal." #property description "Developed by Doug Schaff." #property description "Code adapted from the original TradeStation EasyLanguage version." #property indicator_separate_window #property indicator_buffers 3 #property indicator_plots 1 #property indicator_minimum 0 #property indicator_maximum 100 #property indicator_level1 25 #property indicator_level2 75 #property indicator_width1 2 #property indicator_type1 DRAW_LINE #property indicator_style1 STYLE_SOLID #property indicator_color1 DarkOrchid #property indicator_label1 "STC" //---- Input Parameters input int MAShort = 23; input int MALong = 50; input int Cycle = 10; //---- Global Variables double Factor = 0.5; int BarsRequired; //---- Buffers double MACD[]; double ST[]; double ST2[]; //---- MA Buffers double MAShortBuf[]; double MALongBuf[]; int myShortMA, myLongMA; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ void OnInit() { IndicatorSetString(INDICATOR_SHORTNAME, "STC(" + IntegerToString(MAShort) + ", " + IntegerToString(MALong) + ", " + IntegerToString(Cycle) + ")"); SetIndexBuffer(0, ST2, INDICATOR_DATA); SetIndexBuffer(1, ST, INDICATOR_CALCULATIONS); SetIndexBuffer(2, MACD, INDICATOR_CALCULATIONS); myShortMA = iMA(NULL, 0, MAShort, 0, MODE_EMA, PRICE_CLOSE); myLongMA = iMA(NULL, 0, MALong, 0, MODE_EMA, PRICE_CLOSE); BarsRequired = MALong + Cycle * 2; } //+------------------------------------------------------------------+ //| Schaff Trend Cycle | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { if (rates_total <= BarsRequired) return(rates_total); int counted_bars = prev_calculated; double LLV, HHV; int shift, n = 1, i; // Static variables are used to flag that we already have calculated curves from the previous indicator run static bool st1_pass = false; static bool st2_pass = false; int st1_count = 0; bool check_st1 = false, check_st2 = false; if (counted_bars < BarsRequired) { for (i = 0; i < BarsRequired; i++) ST2[i] = 0; for (i = 0; i < BarsRequired; i++) ST[i] = 0; } if (counted_bars > 0) counted_bars--; shift = counted_bars - BarsRequired + MALong - 1; if (shift < 0) shift = 0; if (CopyBuffer(myShortMA, 0, 0, rates_total, MAShortBuf) != rates_total) return(0); if (CopyBuffer(myLongMA, 0, 0, rates_total, MALongBuf) != rates_total) return(0); while (shift < rates_total) { MACD[shift] = MAShortBuf[shift] - MALongBuf[shift]; if (n >= Cycle) check_st1 = true; else n++; if (check_st1) { // Finding Max and Min on Cycle of MA differrences (MACD) for (i = 0; i < Cycle; i++) { if (i == 0) { LLV = MACD[shift - i]; HHV = MACD[shift - i]; } else { if (LLV > MACD[shift - i]) LLV = MACD[shift - i]; if (HHV < MACD[shift - i]) HHV = MACD[shift - i]; } } // Calculating first Stochastic if (HHV - LLV != 0) ST[shift] = ((MACD[shift] - LLV) / (HHV - LLV)) * 100; else {ST[shift] = ST[shift - 1];} // Smoothing first Stochastic if (st1_pass) ST[shift] = Factor * (ST[shift] - ST[shift - 1]) + ST[shift - 1]; st1_pass = true; // Have enough elements of first Stochastic to proceed to second if (st1_count >= Cycle) check_st2 = true; else st1_count++; if (check_st2) { // Finding Max and Min on Cycle of first smoothed Stoch for (i = 0; i < Cycle; i++) { if (i == 0) { LLV = ST[shift - i]; HHV = ST[shift - i]; } else { if (LLV > ST[shift - i]) LLV = ST[shift - i]; if (HHV < ST[shift - i]) HHV = ST[shift - i]; } } // Calculating second Stochastic if (HHV - LLV != 0) ST2[shift] = ((ST[shift] - LLV) / (HHV - LLV)) * 100; else {ST2[shift] = ST2[shift - 1];} // Smoothing second Stochastic if (st2_pass) ST2[shift] = Factor * (ST2[shift] - ST2[shift - 1]) + ST2[shift - 1]; st2_pass = true; } } shift++; } return(rates_total); } //+----------------------------------------------------
Thank you- Indicator would expire last day in Dec 2012 - Correct?
Yup
In this is the code below, where would I add the above code? I know nothing about coding
Thanks
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
//suggestion.. try like this
//at beginning stage
MqlDateTime urustime;
TimeCurrent(urustime);
if(urustime.mon<=12 && urustime.year<=2012) return(0);
Ok - like this
//+------------------------------------------------------------------+ //| Schaff Trend Cycle | //+------------------------------------------------------------------+
{
MqlDateTime urustime; TimeCurrent(urustime);
if(urustime.mon<=12 && urustime.year<=2012) return(0);
{
int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[],
Ok - like this
Hi,
First, you need to change the condition.
This condition - if(urustime.mon<=12 && urustime.year<=2012) return(0); is not correct, it
will make the ea active only from 2013 and on.. (expired until 12/2012).
it also is redundant (month is always less equal 12, no matter what, so you could just replace it with:
if (urustime.year<=2012) return 0;
Which is equivalent to your condition and still does not do what you need. You should code:
if (urustime.year > 2012 || (urustime.year = 2012 && urustime.month >= 8)) return(); // expiry - 08/2012
Second, you need to put the condition at the beginning of OnCalculate.
Hello Amir... Could you please paste the correct code in its place?
//+------------------------------------------------------------------+ //| Schaff Trend Cycle | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) {
Hello Amir... Could you please paste the correct code in its place?
Hello Gil,
Put the definition in the global definiton area, before the OnInit:
....
MqlDateTime urustime;
void OnInit()...
..
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
TimeCurrent(urustime);
if (urustime.year > 2012 || (urustime.year = 2012 && urustime.month >= 8)) return;
....
}
Hello Gil,
Put the definition in the global definiton area, before the OnInit:
....
MqlDateTime urustime;
TimeCurrent(urustime);
void OnInit()...
..
int OnCalculate(const int rates_total,
const int prev_calculated,
const datetime &time[],
const double &open[],
const double &high[],
const double &low[],
const double &close[],
const long &tick_volume[],
const long &volume[],
const int &spread[])
{
if (urustime.year > 2012 || (urustime.year = 2012 && urustime.month >= 8)) return;
....
}
Do it Simple, use datetime for date
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use