Thinkscript to Pinescript - thinkscript

hello I have this strategy on think or swim I was hoping it could be converted into pine script
input price = close;
input length = 20;
input displace = 0;
plot HMA = MovingAverage(AverageType.HULL, price, length)[-
displace];
HMA.DefineColor("Up", GetColor(1));
HMA.DefineColor("Down", GetColor(0));
HMA.AssignValueColor(if HMA > HMA[1] then HMA.color("Up") else
HMA.color("Down"));
AddOrder(OrderType.BUY_AUTO, HMA > HMA[1]);
AddOrder(OrderType.SELL_AUTO, HMA < HMA[1]);
Alert(HMA > HMA[1] and HMA[1] < HMA[2], "BUY SIGNAL", Alert.BAR,
Sound.Ring);
Alert(HMA < HMA[1] and HMA[1] > HMA[2], "SELL SIGNAL", Alert.BAR,
Sound.Ring);
any help would be amazing thanks

Related

How to read in data from a json file until there is no more data to read in QT

Basically I am using an API to retrieve stock data to me in the form of a ytd so it will return data of the closing price of the stock everyday from january until now. At first I was simply using a for loop and reading until i < json.size() but after figuring out the .size() does not properly return what i need for it to work i am again stuck on this. My code is below
//Retrieves json format of data
Json::Value chartData = IEX::stocks::chartYtd(symbol_std);
//Stores x and y values
QVector<double> time(365), closePrice(365);
//Intialize first vector to first values
closePrice[0] = chartData[0]["close"].asDouble();
time[0] = startYearTime;
//Finds max and min for range
float maxAvg = closePrice[0];
float minAvg = closePrice[0];
//Reads in data from json(historical data 1 day delayed)
for(int i = 1; ; i++)
{
time[i] = startYearTime + 86400*i;
closePrice[i] = (chartData[i]["close"].asDouble());
if((closePrice[i] == 0) && (time[i] != chartData.size() - 1))
{
closePrice[i] = closePrice[i-1];
}
if(closePrice[i] > maxAvg)
{
maxAvg = closePrice[i];
}
else if(closePrice[i] < minAvg)
{
minAvg = closePrice[i];
}
}
The json file looks like this
what can i do to have my code store the "close" value in the json file until there is no more "close" value to read in and then in which it stops, thank you in advance as im a new developer!

How to do Hausman test using sas?

I have panel data and want to do Hausman test for fixed and random effect.
Here is my code:
Proc glm DATA=Sampledata_adjvol;
absorb TRD_STCK_CD;
class TRD_EVENT_ROUFOR;
model adjusted_volume_5 = TRD_EVENT_ROUFOR / solution;
run;
Without using PROC PANEL or the panel procedure, how can I do that test?
Thanks in advance.
proc panel data = Sampledata_adjvol3;
id TRD_STCK_CD DateTime;
class TRD_EVENT_ROUFOR;
model adjusted_volume_5 = TRD_EVENT_ROUFOR / fixone;
run;
* Regression with dummy variables in approach 2;
* Creating dummy variables manually;
data Sampledata_adjvol3_1;
set Sampledata_adjvol3;
if TRD_EVENT_ROUNDED = 34200 then TRD_EVENT_ROUNDED_1 = 1;
else TRD_EVENT_ROUNDED_1 = 0;
if TRD_EVENT_ROUNDED = 36000 then TRD_EVENT_ROUNDED_2 = 1;
else TRD_EVENT_ROUNDED_2 = 0;
if TRD_EVENT_ROUNDED = 37800 then TRD_EVENT_ROUNDED_3 = 1;
else TRD_EVENT_ROUNDED_3 = 0;
if TRD_EVENT_ROUNDED = 39600 then TRD_EVENT_ROUNDED_4 = 1;
else TRD_EVENT_ROUNDED_4 = 0;
if TRD_EVENT_ROUNDED = 41400 then TRD_EVENT_ROUNDED_5 = 1;
else TRD_EVENT_ROUNDED_5 = 0;
if TRD_EVENT_ROUNDED = 43200 then TRD_EVENT_ROUNDED_6 = 1;
else TRD_EVENT_ROUNDED_6 = 0;
run;
proc sort data=Sampledata_adjvol3_1 out=Sampledata_adjvol3_1;
by TRD_STCK_CD DateTime;
run;
proc tscsreg data= Sampledata_adjvol3_1;
model adjusted_volume_5 = TRD_EVENT_ROUNDED_1 TRD_EVENT_ROUNDED_2 TRD_EVENT_ROUNDED_3 TRD_EVENT_ROUNDED_4
TRD_EVENT_ROUNDED_5 TRD_EVENT_ROUNDED_6/ fixone;
id TRD_STCK_CD datetime;
run;

How can I generate dummy variables manually?

Here is the freq procedure:
freq procedure
Why are the TRD_EVENT_ROUFOR_1 & TRD_EVENT_ROUFOR_2 columns totally zero?
Why hasn't it shown the other dummies (ex. TRD_EVENT_ROUFOR_8)?
What is the problem? Which part of my code is wrong?
Here is my code?
DATA Sampledata87_02_Mer_DumVar;
SET Sampledata87_02_Mer ;
IF TRD_EVENT_ROUFOR = '9:00' THEN TRD_EVENT_ROUFOR_1 = 1;
ELSE TRD_EVENT_ROUFOR_1 = 0;
IF TRD_EVENT_ROUFOR = '9:30' THEN TRD_EVENT_ROUFOR_2 = 1;
ELSE TRD_EVENT_ROUFOR_2 = 0;
IF TRD_EVENT_ROUFOR = '10:00' THEN TRD_EVENT_ROUFOR_3 = 1;
ELSE TRD_EVENT_ROUFOR_3 = 0;
IF TRD_EVENT_ROUFOR = '10:30' THEN TRD_EVENT_ROUFOR_4 = 1;
ELSE TRD_EVENT_ROUFOR_4 = 0;
IF TRD_EVENT_ROUFOR = '11:00' THEN TRD_EVENT_ROUFOR_5 = 1;
ELSE TRD_EVENT_ROUFOR_5 = 0;
IF TRD_EVENT_ROUFOR = '11:30' THEN TRD_EVENT_ROUFOR_6 = 1;
ELSE TRD_EVENT_ROUFOR_6 = 0;
IF TRD_EVENT_ROUFOR = '12:00' THEN TRD_EVENT_ROUFOR_7 = 1;
ELSE TRD_EVENT_ROUFOR_7 = 0;
IF TRD_EVENT_ROUFOR = '12:30' THEN TRD_EVENT_ROUFOR_8 = 1;
ELSE TRD_EVENT_ROUFOR_8 = 0;
IF TRD_EVENT_ROUFOR = '13:00' THEN TRD_EVENT_ROUFOR_9 = 1;
ELSE TRD_EVENT_ROUFOR_9 = 0;
RUN;
PROC FREQ DATA=Sampledata87_02_Mer_DumVar;
TABLES TRD_EVENT_ROUFOR*TRD_EVENT_ROUFOR_1*TRD_EVENT_ROUFOR_2*TRD_EVENT_ROUFOR_3*TRD_EVENT_ROUFOR_4*TRD_EVENT_ROUFOR_5 / list ;
RUN;
And, here is the CONTENTS Procedure:
CONTENTS Procedure
For the first two variables '9:00' and '9:30' I'll guess these are right justified in the character variable $5. and are actually ' 9:00' and ' 9:30'.
Usually you don't need to create dummies in SAS you can use the CLASS statement instead. If you do want to create them there are two procedures that are helpful PROC GLMMOD and PROC TRANSREG.
Including example data is usually helpful.

arc4random() stopped working after project update, Thread 1: EXC_ARITHMETIC

I got a warning on xcode 6.0.1 that I needed to update my project, so I did...
...but then I got issues with arc4random() % instead
Everything was working fine before this update, but now I get the following message:
"Thread 1: EXC_ARITHMETIC (code = EXC_1386_DIV, Subcode = 0x0) and the game crashes.
I tried with arc4random_uniform but the game seems to "pause" and nothing happens. What I mean is that I could see that it entered the if(bType == pt || bType == pl) statement but there is seems to "pause" and loop endlessly.
any suggestions?
-(void)placeInGrid:(CGPoint)place pt:(int)pt pl:(int)pl amount:(int)amountOfbricks{
CCLOG(#"BRICKS:placeInGrid");
//CCLOG(#"pt %d", pt);
//CCLOG(#"pl %d", pl);
int bType = arc4random() % amountOfbricks;
//int bType = arc4random_uniform(amountOfbricks);
if(bType == pt || bType == pl){
CCLOG(#"bType == pt || bType == pl");
[self placeInGrid:place pt:pt pl:pl amount:amountOfbricks];
return;
}
else{
CCLOG(#"else");
CCSpriteBatchNode * b = (CCSpriteBatchNode *)[theGame getChildByTag:kSSheet];
mySprite = [CCSprite spriteWithBatchNode:b rect:[self setBrickType:bType]];
[b addChild:mySprite z:1];
self.bricksType =bType;
[self.mySprite setPosition:place];
}
}
UPDATE:
the if-else statement below looks for saved data at the beginning of the game, to see if it´s a saved game or a new game.
The problem as it seems, after the project update is that the game thinks that there is already saved data and it goes to the first if statement ( if(gameData)), causing amountofbricks to be equal to 0, instead of going into the else statement where amountofbricks is equal to 4.
I don´t know how to solve this issue.
if ([[GameManager sharedGameManager] isContinuePressed] == NO && [[GameManager sharedGameManager] isNewPressed] == YES) {
if(gameData){
CCLOG(#"gameData && isContinuePressed == NO && isNewPressed == YES");
//Set the local instance of myobject to the object held in the gameState filler with the key "myObject"
level = 1;
[[GameManager sharedGameManager] setHScore:[decoder decodeIntegerForKey:#"HighScore"]];
highscore = [[GameManager sharedGameManager] ReturnHScore];
countTime = 300;
AmountOfBricks = [[GameManager sharedGameManager] ReturnAmountOfBricks];
BeginningOfGame = YES;
CCLOG(#"AmountOfBricks %d", AmountOfBricks);
}
else{
CCLOG(#"!gameData && isContinuePressed == NO && isNewPressed == YES");
if([[GameManager sharedGameManager]isThereASavedGame] ==YES){
CCLOG(#"isThereASavedGame == YES");
score = 0;
highscore = [[GameManager sharedGameManager] ReturnHScore];
level = 1;
countTime = 300;
AmountOfBricks = 4;
BeginningOfGame = YES;
CCLOG(#"AmountOfBricks %d", AmountOfBricks);
}
else{
CCLOG(#"isThereASavedGame == NO");
score = 0;
highscore = 0;
level = 1;
countTime = 300;
AmountOfBricks = 4;
BeginningOfGame = YES;
CCLOG(#"AmountOfBricks %d", AmountOfBricks);
}
}
}
UPDATE: I found the issue.
the issue was in my game manager.m file.
NSMutableData *gameData;
NSKeyedUnarchiver *decoder = nil;
NSString *documentPath = [documentsDirectory stringByAppendingPathComponent: #"gameState.dat"];
gameData = [NSData dataWithContentsOfFile:documentPath];//before the update, I as using this line. was working perfectly. after the update I got a warning on this line "incompatible pointer" and xcode recommended to update to the line below but the line below started to return a zero value. which caused the game to crash.
//gameData = [NSMutableData dataWithData:[NSData dataWithContentsOfFile:documentPath]];
I wager amountOfBricks is 0. You can't modulo by 0 like you can't divide by 0.

Day(s) of week selection from QT checkbox to Postgresql

I have a group of checkboxes representing the days of a week in my Qt application GUI and I select one or many days, and depending on which boxes are checked, pass a query string to PostgreSQL in order to display certain data on those days -e.g. if I checked monday and wednesday, extract (dow from timestamp) = 1 or extract(dow from timestamp) = 3 should be added to my query. I have just typed a crude solution -though haven't tested yet as I write this-, but I was wondering if there is a shorter -and more elegant- approach that I'm missing out here. The code is as below: -the queryAdditionCalltimePart and queryAdditionCallStampPart strings are later added to the relevant parts of my main query's QString before the main query is executed-
bool checkboxArray[7];
bool mult = false;
checkboxArray[0] = this->ui->checkBoxMonday->isChecked();
checkboxArray[1] = this->ui->checkBoxTuesday->isChecked();
checkboxArray[2] = this->ui->checkBoxWednesday->isChecked();
checkboxArray[3] = this->ui->checkBoxThursday->isChecked();
checkboxArray[4] = this->ui->checkBoxFriday->isChecked();
checkboxArray[5] = this->ui->checkBoxSaturday->isChecked();
checkboxArray[6] = this->ui->checkBoxSunday->isChecked();
QString queryAdditionCalltimePart = "";
QString queryAdditionCalStampPart = "";
int count = 0;
queryAdditionCalltimePart.append("(");
queryAdditionCalStampPart.append("(");
for(int i = 0; i < 7; i++)
{
if(checkboxArray[i] == true)
{
count++;
}
}
int x = 0;
for(int i = 0; i < 7; i++)
{
if(checkboxArray[i] == true)
{
queryAdditionCalltimePart.append("(SELECT EXTRACT(DOW FROM calltime) = '" +QString::number(i+1)+"')");
queryAdditionCalStampPart.append("(SELECT EXTRACT(DOW FROM cal.stamp) = '" +QString::number(i+1)+"')");
}
if(count > 1 && checkboxArray[i] == true)
{
if(x == count - 1)
{
}
else
{
queryAdditionCalltimePart.append("OR");
queryAdditionCalStampPart.append("OR");
x++;
}
}
}
queryAdditionCalltimePart.append(")");
queryAdditionCalStampPart.append(")");
You can add properties to any widget in Qt, http://qt-project.org/doc/qt-4.8/qobject.html#setProperty. The property can have any information that you want.
In your particular case, it would be cleaner to attach the SQL string as a property for each checkbox.
this->ui->checkBoxMonday->setProperty("sql",
"(SELECT EXTRACT(DOW FROM calltime) = '" +QString::number(i+1)+"') OR ";
Once you receive the user input, simply append the check box properties and remove the final OR.