Announcement

Collapse
No announcement yet.

Alert does not fire

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Alert does not fire

    I am adding an error handling routine to one of my backtest strategies. Everything appears to be functioning except an alert does not fire. If I put the Error checking code outside of the Initialization so it runs on every bar instead of just the first bar, the Alerts fire normally. Anyone have any suggestions as to what may be wrong?

    Thanks, Greg

    Here are the relevant parts of the code:

    /*Initialize Global System Variables */
    var sVersion = "V2-0-0";

    var bInit = false;// Initialization flag
    var bError = false;// Error flag
    var vDay = null; // Current Day of Month

    function preMain()
    {
    setPriceStudy(true);
    setStudyTitle("BT System A " + sVersion);
    setShowCursorLabel(false);
    setShowTitleParameters(false);
    setComputeOnClose();//Delete to have study execute on every tick
    }

    function main(fpEntrySize, fpEMA1, fpEMA2, fpEMA3, fpEMA4, fpT1Size, fpT2Size, fpT3Size, fpT4Size)

    {
    // Initialization
    if (!bInit)
    {
    vDay = getDay();
    bInit = true;
    if ((fpT1Size + fpT2Size + fpT3Size + fpT4Size) - fpEntrySize != 0)
    {
    Alert.playSound("swoosh.wav");// TODO This code does not work
    Alert.addToList("none", "Target Sizes Not Equal to Entry Size", Color.black, Color.red); // TODO This code does not work
    debugPrintln((fpT1Size + fpT2Size + fpT3Size + fpT4Size) + " " + fpEntrySize);
    bError = true;
    } // endif
    } // endif

    // Exit on Error
    if (bError) return;
    .
    .
    .

  • #2
    Re: Alert does not fire

    Greg
    That is happening because the initialization routine is executed only once on the first bar when the efs is loaded [or reloaded] and to my knowledge alerts are executed only on bar index 0
    Alex


    Originally posted by GregSchroeder
    I am adding an error handling routine to one of my backtest strategies. Everything appears to be functioning except an alert does not fire. If I put the Error checking code outside of the Initialization so it runs on every bar instead of just the first bar, the Alerts fire normally. Anyone have any suggestions as to what may be wrong?

    Thanks, Greg

    Here are the relevant parts of the code:

    /*Initialize Global System Variables */
    var sVersion = "V2-0-0";

    var bInit = false;// Initialization flag
    var bError = false;// Error flag
    var vDay = null; // Current Day of Month

    function preMain()
    {
    setPriceStudy(true);
    setStudyTitle("BT System A " + sVersion);
    setShowCursorLabel(false);
    setShowTitleParameters(false);
    setComputeOnClose();//Delete to have study execute on every tick
    }

    function main(fpEntrySize, fpEMA1, fpEMA2, fpEMA3, fpEMA4, fpT1Size, fpT2Size, fpT3Size, fpT4Size)

    {
    // Initialization
    if (!bInit)
    {
    vDay = getDay();
    bInit = true;
    if ((fpT1Size + fpT2Size + fpT3Size + fpT4Size) - fpEntrySize != 0)
    {
    Alert.playSound("swoosh.wav");// TODO This code does not work
    Alert.addToList("none", "Target Sizes Not Equal to Entry Size", Color.black, Color.red); // TODO This code does not work
    debugPrintln((fpT1Size + fpT2Size + fpT3Size + fpT4Size) + " " + fpEntrySize);
    bError = true;
    } // endif
    } // endif

    // Exit on Error
    if (bError) return;
    .
    .
    .

    Comment

    Working...
    X