Jump to content
Medved Trader Forums

Mike Medved

Administrators
  • Posts

    1,543
  • Joined

  • Last visited

  • Days Won

    124

Posts posted by Mike Medved

  1. well.. you have Qty as 30/(Ask-PriceAtMouse). Should really be floor(30/(Ask-PriceAtMouse)) - because quantity is an integer.

    So then the total amount of the transaction would be (since it is a Market Buy, let's assume it is at Ask)

    Ask * floor(30/(Ask-PriceAtMouse))

    You don't want that to be more than $10k, so that amount would be

    Min(10000, Ask * floor(30/(Ask-PriceAtMouse)))

    Thus the appropriate quantity should be that amount divided by Ask (and floor taken for it so that it is integer)

    floor(Min(10000, Ask * floor(30/(Ask-PriceAtMouse))) / Ask)


     



     

  2. When I send out the backfillAndGetCandles, I first receive these messages

    {
      "cmd": "backfill",
      "reqID": "1246",
      "success": "OK",
      "resultcode": 200,
      "result": {
        "action": "started",
        "type": "OHLC",
        "sym": "NVDA"
      }
    }

    ... and then


    {
      "cmd": "backfill",
      "reqID": "1246",
      "success": "OK",
      "resultcode": 200,
      "result": {
        "action": "finished",
        "type": "OHLC",
        "sym": "NVDA"
      }
    }
     

    ... and only after that, the

    {
      "cmd": "getCandles",
      "reqID": "1246",
      "success": "OK",

    ... etc.


    Is this not what happens for you?

  3. If you open a historical chart for stock A, set VWAP to anchor at 1/1/2020 then close it.

    Then open a historical chart for stock B, set VWAP to anchor at 1/1/2021 then close it.

    Then re-open historical chart for stock A, the VWAP anchor will be remembered.

     

    But, if you switch charts by either typing a new symbol in the chart or by using linked symbols, the anchor date (or any other parameters for any other indicators) won't change.

  4. Note that everything *after* MainCalculation is just standard code inserted by MT when you make it a state machine.
    Also - to make it work right, it has to be run as an Intraday scan, with the extended hours set to Always.
    
    ====================================================================================================================
    
    private struct PaintbarState
    {
        public Double PreMarketVolume;
    }
    int LastDayNumber = -1;
    
    FIFOQueue PreMarketVolumes = new FIFOQueue(5);  // averaging on 5 days period
    Boolean WasPreMarket       = false;
    
    public void MainCalculation()
    {
        SetDaysNeeded(5); // need 5 day's data for this to work
        if (TradingDay.DayNumber != LastDayNumber)  // initialize to 0 start of every day
        {
            CurrentState.PreMarketVolume = 0;
            LastDayNumber                = TradingDay.DayNumber;
        }
        if (TradingDay.IsPreMarket)
        {
            CurrentState.PreMarketVolume += BarVolume;
            WasPreMarket = true;
        }
        else
        {
            if (WasPreMarket) // add the premarket volume AFTER the premarket ends to the average queue
            {
                WasPreMarket = false;
                PreMarketVolumes.Add(CurrentState.PreMarketVolume);
            }
        }
    
        SetScanResultColumnName(0, "Avg Premarket");
        SetScanResult(0, Convert.ToInt64(PreMarketVolumes.Average));
    }
    
    /// <summary>
    /// INITIALIZES paintbar. Is called at start of paintbar calculation, should be used to initialize anything needed for the paintbar
    /// NOTE: do NOT initialize the CurrentState here - the PaintbarClearState will be called AFTER this call, and will wipe it out.
    /// </summary>
    private void PaintbarInitialize()
    {
    
    }
    
    
    /// <summary>
    /// Holds current PB state - use to calc PB, changes to it carry over to next PB calc
    /// </summary>
    private PaintbarState CurrentState;
    
    /// <summary>
    /// Holds saved PB state - internal
    /// </summary>
    private PaintbarState SavedState;
    
    /// <summary>
    /// Is called at start of paintbar calculation, should be used to clear the paintbar state
    /// and initialize whatever variables you place into it. This is called AFTER PaintbarInitialize
    /// </summary>
    private void PaintbarClearState()
    {
        CurrentState = new PaintbarState();
    }
    
    /// <summary>
    /// Saves paintbar state (called internally).
    /// </summary>
    private void PaintbarSaveState()
    {
        SavedState = CurrentState;
    }
    
    /// <summary>
    /// Restores paintbar state (called internally).
    /// </summary>
    private void PaintbarRestoreState()
    {
        CurrentState = SavedState;
    }
    • Like 1
  5. Yes, scan results only show if the condition is true on the current - last - candle of the chart. Unlike the paintbar that can show if the condition was true on any candle in the chart.

    That's the whole point of the scanner - you can scan 3000 symbols and show only the tickers for which the condition is NOW true.  You can, of course, write the scanner with a condition "if this condition was true in any of the last N candles", too.

  6. Thing is, 4pm candle (anything that is traded at or after 4pm) is considered afterhours.

    IsAfterHours in TradingDay is defined as

                    Timestamp >= SessionEnd && Timestamp <= DayEnd

    So instead of IsAfterHours in your code, if you want to give a 1 min buffer you can just say

        Timestamp >= SessionEnd.SessionEnd.AddMinutes(1)

     

×
×
  • Create New...