private void OnInstrumentUpdate(Tick m_Tick) { m_TickList.Add(m_Tick); m_MFI = 50; m_MF = 0; // Begin calculation if (m_Ticks > 0 && m_TickList.Count > m_Ticks) { // Calculate the RS and RSI. m_UpTotal = 0; m_DownTotal = 0; for (int i = m_TickList.Count - m_Ticks; i < m_TickList.Count - 1; i++) { m_WeightedDiff = (m_TickList[i].Price - m_TickList[i - 1].Price) * m_TickList[i].Qty; if (m_WeightedDiff > 0) { m_UpTotal += m_WeightedDiff; } else if (m_WeightedDiff < 0) { m_DownTotal -= m_WeightedDiff; } } m_MF = m_UpTotal / m_DownTotal; m_MFI = 100 - 100 / (1 + m_MF); Debug.WriteLine(m_MFI); //// Set the Value State. //if (m_MFI < 40) // m_State = Value_State.LOW; //else if (m_MFI < 60) // m_State = Value_State.MID; //else // m_State = Value_State.HIGH; } // START/STOP Switch if (m_Go) { // If we already have a position on, and have either met out target or stop price, get out. if (m_Position > 0 && (m_Tick.Price > m_Target || m_Tick.Price < m_Stop)) { m_Bool = m_Instrument.EnterOrder("S", m_Qty, "TARGET/STOP OUT"); } if (m_Position < 0 && (m_Tick.Price < m_Target || m_Tick.Price > m_Stop)) { m_Bool = m_Instrument.EnterOrder("B", m_Qty, "TARGET/STOP OUT"); } // First time only and on reset, set initial state. if (m_Start) { if (m_MFI >= 60) { m_State = Value_State.HIGH; } else if (m_MFI >= 40) { m_State = Value_State.MID; } else { m_State = Value_State.LOW; } m_Start = false; } // Has there been oversold? if (m_MFI < 40 && m_State != Value_State.LOW) { // Change state. m_State = Value_State.LOW; // If we are already short, first get flat. if (m_Position < 0) { m_Bool = m_Instrument.EnterOrder("B", m_Qty, "GET OUT"); } // Go long. m_Bool = m_Instrument.EnterOrder("B", m_Qty, "OPEN"); // Set target price and stop loss price. m_Target = m_Tick.Price + m_TargetTicks * m_Instrument.TickSize(); m_Stop = m_Tick.Price - m_StopTicks * m_Instrument.TickSize(); } // Has there been overbought? if (m_MFI >= 60 && m_State != Value_State.HIGH) { // Change state. m_State = Value_State.HIGH; // If we are already long, first get flat. if (m_Position > 0) { m_Bool = m_Instrument.EnterOrder("S", m_Qty, "GET OUT"); } // Go short. m_Bool = m_Instrument.EnterOrder("S", m_Qty, "OPEN"); // Set target price and stop loss price. m_Target = m_Tick.Price - m_TargetTicks * m_Instrument.TickSize(); m_Stop = m_Tick.Price + m_StopTicks * m_Instrument.TickSize(); } } // Send the data to the GUI. OnSystemUpdate(m_Tick.Price, m_Tick.Qty, m_MFI, m_MF, m_Target, m_Stop); }
private void OnInstrumentUpdate(Tick m_Tick) { m_TickList.Add(m_Tick); m_K = 0; m_D = 0; // Begin calculating if (m_Ticks > 0 && m_TickList.Count > m_Ticks) { // Calculate the K and D values. m_Max = 0; m_Min = 1000000000; for (int i = m_TickList.Count - m_Ticks; i < m_TickList.Count - 1; i++) { m_Max = Math.Max(m_Max, m_TickList[i].Price); m_Min = Math.Min(m_Min, m_TickList[i].Price); } m_RSV.Add((m_TickList.Last().Price - m_Min) / (m_Max - m_Min) * 100); //Debug.WriteLine(m_RSV.Last()); if (m_RSV.Count >= 3) { m_D = (m_RSV[m_RSV.Count - 1] + m_RSV[m_RSV.Count - 2] + m_RSV[m_RSV.Count - 3]) / 3; } m_K = m_RSV.Last(); //Debug.WriteLine(m_K); //Debug.WriteLine(m_D); //// Set the Cross State. //if (m_K > m_D) // m_State = Cross_State.ABOVE; //else // m_State = Cross_State.BELOW; } // START/STOP Switch if (m_Go) { // If we already have a position on, and have either met out target or stop price, get out. if (m_Position > 0 && (m_Tick.Price > m_Target || m_Tick.Price < m_Stop)) { m_Bool = m_Instrument.EnterOrder("S", m_Qty, "TARGET/STOP OUT"); } if (m_Position < 0 && (m_Tick.Price < m_Target || m_Tick.Price > m_Stop)) { m_Bool = m_Instrument.EnterOrder("B", m_Qty, "TARGET/STOP OUT"); } // First time only and on reset, set initial state. if (m_Start) { if (m_K > m_D) { m_State = Cross_State.ABOVE; } else { m_State = Cross_State.BELOW; } m_Start = false; } // Has there been a crossover up? if (m_K > m_D && m_State == Cross_State.BELOW) { // Change state. m_State = Cross_State.ABOVE; // If we are already short, first get flat. if (m_Position < 0) { m_Bool = m_Instrument.EnterOrder("B", m_Qty, "GET OUT"); } // Go long. m_Bool = m_Instrument.EnterOrder("B", m_Qty, "OPEN"); // Set target price and stop loss price. m_Target = m_Tick.Price + m_TargetTicks * m_Instrument.TickSize(); m_Stop = m_Tick.Price - m_StopTicks * m_Instrument.TickSize(); } // Has there been a crossover down? if (m_K < m_D && m_State == Cross_State.ABOVE) { // Change state. m_State = Cross_State.BELOW; // If we are already long, first get flat. if (m_Position > 0) { m_Bool = m_Instrument.EnterOrder("S", m_Qty, "GET OUT"); } // Go short. m_Bool = m_Instrument.EnterOrder("S", m_Qty, "OPEN"); // Set target price and stop loss price. m_Target = m_Tick.Price - m_TargetTicks * m_Instrument.TickSize(); m_Stop = m_Tick.Price + m_StopTicks * m_Instrument.TickSize(); } } // Send the data to the GUI. OnSystemUpdate(m_Tick.Price, m_Tick.Qty, m_D, m_K, m_Target, m_Stop); }
private void OnInstrumentUpdate(Tick m_Tick) { m_TickList.Add(m_Tick); m_FI = 0; m_F = 0; // Begin calculation if (m_Ticks > 0 && m_TickList.Count > m_Ticks) { // Calculate the Force and Force Index. for (int i = m_TickList.Count - m_Ticks; i < m_TickList.Count - 1; i++) { m_WeightedDiff = (m_TickList[i].Price - m_TickList[i - 1].Price) * m_TickList[i].Qty; } m_F += m_WeightedDiff; m_FI = m_F / m_Ticks; Debug.WriteLine(m_FI); } // START/STOP Switch if (m_Go) { // If we already have a position on, and have either met out target or stop price, get out. if (m_Position > 0 && (m_Tick.Price > m_Target || m_Tick.Price < m_Stop)) { m_Bool = m_Instrument.EnterOrder("S", m_Qty, "TARGET/STOP OUT"); } if (m_Position < 0 && (m_Tick.Price < m_Target || m_Tick.Price > m_Stop)) { m_Bool = m_Instrument.EnterOrder("B", m_Qty, "TARGET/STOP OUT"); } // First time only and on reset, set initial state. if (m_Start) { if (m_FI > 0) { m_State = Cross_State.ABOVE; } else { m_State = Cross_State.BELOW; } m_Start = false; } // Has there been a crossover up? Buy Signal if (m_FI > 0 && m_State == Cross_State.BELOW) { // Change state. m_State = Cross_State.ABOVE; // If we are already short, first get flat. if (m_Position < 0) { m_Bool = m_Instrument.EnterOrder("B", m_Qty, "GET OUT"); } // Go long. m_Bool = m_Instrument.EnterOrder("B", m_Qty, "OPEN"); // Set target price and stop loss price. m_Target = m_Tick.Price + m_TargetTicks * m_Instrument.TickSize(); m_Stop = m_Tick.Price - m_StopTicks * m_Instrument.TickSize(); } // Has there been overbought? Sell Signal if (m_FI < 0 && m_State == Cross_State.ABOVE) { // Change state. m_State = Cross_State.BELOW; // If we are already long, first get flat. if (m_Position > 0) { m_Bool = m_Instrument.EnterOrder("S", m_Qty, "GET OUT"); } // Go short. m_Bool = m_Instrument.EnterOrder("S", m_Qty, "OPEN"); // Set target price and stop loss price. m_Target = m_Tick.Price - m_TargetTicks * m_Instrument.TickSize(); m_Stop = m_Tick.Price + m_StopTicks * m_Instrument.TickSize(); } } // Send the data to the GUI. OnSystemUpdate(m_Tick.Price, m_Tick.Qty, m_FI, m_F, m_Target, m_Stop); }
private void OnInstrumentUpdate(Tick m_Tick) { m_TickList.Add(m_Tick); m_Max = m_Tick.Price; m_Min = m_Tick.Price; // Begin calculation if (m_Ticks > 0 && m_TickList.Count > m_Ticks) { // Calculate the Force and Force Index. m_Max = 0; m_Min = 999999999; for (int i = m_TickList.Count - m_Ticks; i < m_TickList.Count - 1; i++) { m_Max = Math.Max(m_Max, m_TickList[i].Price); m_Min = Math.Min(m_Min, m_TickList[i].Price); } Debug.WriteLine(m_Max); } // START/STOP Switch if (m_Go) { // If we already have a position on, and have either met out target or stop price, get out. if (m_Position > 0 && (m_Tick.Price > m_Target || m_Tick.Price < m_Stop)) { m_Bool = m_Instrument.EnterOrder("S", m_Qty, "TARGET/STOP OUT"); } if (m_Position < 0 && (m_Tick.Price < m_Target || m_Tick.Price > m_Stop)) { m_Bool = m_Instrument.EnterOrder("B", m_Qty, "TARGET/STOP OUT"); } // First time only and on reset, set initial state. if (m_Start) { if (m_Tick.Price > m_Max) { m_State = Value_State.HIGH; } else if (m_Tick.Price >= m_Min) { m_State = Value_State.MID; } else { m_State = Value_State.LOW; } m_Start = false; } // Has there been a crossover up? Buy Signal if (m_Tick.Price > m_Max && m_State != Value_State.HIGH) { // Change state. m_State = Value_State.HIGH; // If we are already short, first get flat. if (m_Position < 0) { m_Bool = m_Instrument.EnterOrder("B", m_Qty, "GET OUT"); } // Go long. m_Bool = m_Instrument.EnterOrder("B", m_Qty, "OPEN"); // Set target price and stop loss price. m_Target = m_Tick.Price + m_TargetTicks * m_Instrument.TickSize(); m_Stop = m_Tick.Price - m_StopTicks * m_Instrument.TickSize(); } // Has there been overbought? Sell Signal if (m_Tick.Price < m_Min && m_State != Value_State.LOW) { // Change state. m_State = Value_State.LOW; // If we are already long, first get flat. if (m_Position > 0) { m_Bool = m_Instrument.EnterOrder("S", m_Qty, "GET OUT"); } // Go short. m_Bool = m_Instrument.EnterOrder("S", m_Qty, "OPEN"); // Set target price and stop loss price. m_Target = m_Tick.Price - m_TargetTicks * m_Instrument.TickSize(); m_Stop = m_Tick.Price + m_StopTicks * m_Instrument.TickSize(); } } // Send the data to the GUI. OnSystemUpdate(m_Tick.Price, m_Tick.Qty, m_Min, m_Max, m_Target, m_Stop); }